Sujet : Re: TERPRI
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 11. Jul 2025, 16:45:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104rbhs$1itot$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
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))))))