[racket] Style. for/fold for/list for/lists
You have hit limitations of the for/fold macros. I wrote an extension for controlling the way values get accumulated, along with post-processing like list reversal. Let me know what you think!
https://github.com/ianj/nifty-macros/tree/master/for-acc
-Ian
----- Original Message -----
From: Roman Klochkov <kalimehtar at mail.ru>
To: users at racket-lang.org
Sent: Sat, 18 Jan 2014 06:25:10 -0500 (EST)
Subject: [racket] Style. for/fold for/list for/lists
Where can I find style guide for these
for/lists:
I have to duplicate values names:
(define-values ([(desc-args lengths add-data)
(for/lists (desc-args lengths add-data) ([arg (in-list %args)])
....)) is it ok? Or better
(define-values ([(desc-args lengths add-data)
(for/lists (a b c) (...) ...))
?
for/fold has no "return" clause. So I have to do
(call-with-values
(for/fold (acc1 acc2 sum) (...) ...)
(lambda (acc1 acc2 sum) (reverse acc1) (reverse acc2) sum))
And for/list doesn't allow to add several items to resulting list in one round.
Even with for/fold it gives
(reverse
(for/fold (acc) ([item (in-list list)])
(values (cons (get-val1 item)
(cons (get-val2 item) acc)))))
Awful, especially for reading.
It is clumsy and unobvious.
In Common Lisp iterate I could do
(iter (...)
(collect (foo) into acc1)
(collect (bar) into acc2)
(summing ... into sum)
(finally (return acc1 acc2 sum)))
http://common-lisp.net/project/iterate/doc/index.html
Is there something similar?
--
Roman Klochkov