• Re: TERPRI

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Fri Jul 11 08:01:17 2025
    From Newsgroup: comp.lang.scheme

    Rob Warnock wrote:

    (running small "scripts" 100 times and histogramming the results), and I needed to sum the "user" and "system" times reported by the "csh" builtin "time" command (since the "total" time has one fewer digits of precision). Here's what I wrote:

    #!/usr/local/bin/cmucl -script

    ;;; Script to sum the first two times in a "csh" "time" output:
    ;;; 0.046u 0.007s 0:00.06 66.6% 147+3008k 0+0io 0pf+0w

    (defun sum-u-s (line)
    (+ (read-from-string line nil nil :start 0 :end (position #\u line))
    (read-from-string line nil nil :start (1+ (position #\space line))
    :end (position #\s line))))

    (loop for line = (read-line *standard-input* nil nil)
    while line
    do (format t "~5,3f~%" (sum-u-s line)))

    Trivial? Yes, but it's what I needed at the moment, and it was the
    language I wa able to do it in fastest.

    Gauche Scheme:

    (until (read-line) eof-object? => line
    (with-input-from-string (regexp-replace-all #/[us]/ line "")
    (cut print (+ (read) (read)))))
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Fri Jul 11 15:45:01 2025
    From Newsgroup: comp.lang.scheme

    B. Pym wrote:

    Rob Warnock wrote:

    (running small "scripts" 100 times and histogramming the results), and I needed to sum the "user" and "system" times reported by the "csh" builtin "time" command (since the "total" time has one fewer digits of precision). Here's what I wrote:

    #!/usr/local/bin/cmucl -script

    ;;; Script to sum the first two times in a "csh" "time" output:
    ;;; 0.046u 0.007s 0:00.06 66.6% 147+3008k 0+0io 0pf+0w

    (defun sum-u-s (line)
    (+ (read-from-string line nil nil :start 0 :end (position #\u line))
    (read-from-string line nil nil :start (1+ (position #\space line))
    :end (position #\s line))))

    (loop for line = (read-line *standard-input* nil nil)
    while line
    do (format t "~5,3f~%" (sum-u-s line)))

    Trivial? Yes, but it's what I needed at the moment, and it was the
    language I wa able to do it in fastest.

    Gauche Scheme:

    (until (read-line) eof-object? => line
    (with-input-from-string (regexp-replace-all #/[us]/ line "")
    (cut print (+ (read) (read)))))

    Without using regular expressions it's actually shorter.
    I ought to have done it this way to begin with.

    (use srfi-13) ;; string-delete

    (until (read-line) eof-object? => line
    ;; In the line below, #[us] is a character set.
    (with-input-from-string (string-delete #[us] line)
    (cut print (+ (read) (read)))))


    Using lambda instead of cut;

    (until (read-line) eof-object? => line
    ;; In the line below, #[us] is a character set.
    (with-input-from-string (string-delete #[us] line)
    (lambda()
    (print (+ (read) (read))))))


    Using a predicate:

    (until (read-line) eof-object? => line
    (with-input-from-string (string-delete char-lower-case? line)
    (lambda()
    (print (+ (read) (read))))))



    --- Synchronet 3.21a-Linux NewsLink 1.2