Sujet : Re: A simple Lisp program -- algorithm and speed issues
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.lisp comp.lang.schemeDate : 20. Sep 2024, 22:28:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240920140513.755@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-20, B. Pym <
Nobody447095@here-nor-there.org> wrote:
The file contains:
>
foo 5
bar 20
baz 4
foo 6
foobar 23
foobar 3
bar 68
baz 33
>
Gauche Scheme
Given: 13 more lines of macro cruft, half of which
simulates optional arguments with default values.
(define (process file)
(let1 result '()
(with-input-from-file file
(cut generator-for-each
(lambda (item)
(ainc! result (symbol->string item) (read)))
read))
(sort result string<? car)))
>
(process "output.dat")
===>
(("bar" . 88) ("baz" . 37) ("foo" . 11) ("foobar" . 26))
TXR Lisp:
1> (flow "file"
file-get-objects
(tuples 2)
(group-map [chain car symbol-name] (op sum @1 cadr))
hash-alist
(sort @1 : car))
(("bar" . 88) ("baz" . 37) ("foo" . 11) ("foobar" . 26))
Given:
Vanilla installation of TXR.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca