[racket-dev] for/... improvement. #:filter
I propose to add yet one keyword to for/foldX/derived/break (and so to all for/... syntaxes).
Reason:
If one need to filter the results of body before collecting them in list/vector/sum/..., there are two options:
1. (filter filter-func (for/list ...)) : doubles memory consumption and slower
2. (for/list (exprs ...) body ...) => (for/list (exprs ... #:when #t (res (in-value (begin body ...))) #:when (filter-func res)) res). Works, but very clumsy.
I propose syntax
(for/list (exprs ...) body ...) => (for/list (exprs ... #:filter filter-func) body ...) with the same behavior as in 2.
Syntax:
#:filter filter-func = (thunk* #t)
Expects function with the same number of arguments as the result of for/... body should return values. Applied to results of body, and collected only if filter-func returns #t.
Implementation:
Minor changes in for.rkt in (define-syntax (for/foldX/derived stx) ...) and in documentation. If you busy, I may do it myself and make pull request.
To think about:
How many values should return filter-func in (for/lists ...). Only one or as many as values of body. I don't know what is more natural.
--
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130911/804a251f/attachment.html>