[racket-dev] PLaneT Library of Iterations/Comprehensions
Dave,
Thanks a bunch for pointing out the untyped code! I have a few questions below, mostly trying to understand the behavior of the macros and reconcile it with their names.
I'm not sure that I understand for/foldl and friends. I think of the functions foldl (and foldr) as taking *one* accumulator, and filtering it through a function applied to each of the members of a sequence or sequences---that is, there are many function arguments, but only one accumulator. But, the foldl here looks like
(define-syntax (for/foldl stx)
(syntax-case stx ()
((for/foldl accums (for-clause ...) body ...)
(syntax/loc stx
(call-with-values
(lambda ()
(for/fold accums (for-clause ...) body ...))
(lambda args (car args)))))))
That is, it has many accumulators, but returns only the first. (I tried defining the code you linked to at the REPL, and it barfed on some of the ...'s, so I wasn't able to test this assertion. I'm sure that I'm just missing some libraries.) Am I confused? This sounds more like for/fold/head, or for/fold/first, or something like that?
I'm similarly a bit unhappy with the name for for/filter. The filter procedure takes a predicate, and removes any items from its list argument that don't satisfy the predicate. The for/filter macro is like a (hypothetical) for/lists, followed by a removal of the false elements. Is there possible a better name for this? How often do you find yourself using the multi-valued version (i.e. could we have a single-valued for/not-false or something, that gets most of the use cases)?
I like for/append without reservation, and have added it to my local iteration branch, and I'll forward it to Sam once I've built the code and it passes some tests. Thanks again for suggesting these forms, Dave.
Will
On Aug 24, 2010, at 2:55 AM, Dave Gurnell wrote:
> I use these guys all the time:
>
> http://github.com/untyped/unlib/blob/master/for.ss
>
> No guarantees that I'm not duplicating other peoples' efforts.
>
> Cheers,
>
> -- Dave
>
> On 22 Aug 2010, at 07:26, Noel Welsh wrote:
>
>> Hi Will,
>>
>> My "numerics" package on Github has for/vector with some slight
>> extensions to yours. I think it also has more error checking so you
>> might want to look at it. I also have for/fold/vector and some
>> sequence abstractions. The code is all parameterised at expansion time
>> by the vector representation.
>>
>> http://github.com/noelwelsh/numeric
>>
>> N.
>>
>>
>> On Wed, Aug 18, 2010 at 5:02 PM, Will M. Farr <wmfarr at gmail.com> wrote:
>>> Hello all,
>>>
>>> I've been thinking for a while about putting together a PLaneT library of some iteration/comprehension forms that I often use that are not found in the racket core. Right now, I have a small it-comp.plt local PLaneT package that contains
>>>
>>> for/vector
>>> for/flvector
>>> in-flvector
>>>
>>> The for/... forms have the option of having a first expression that gives the length of the resulting object (similar to srfi-42's vector-of-length-ec form) to allow generating more efficient code:
>>>
>>> (for/vector ((x (in-range 3))) x) => (vector 0 1 2)
>>> (for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently
>>>
>>> I'll be adding more forms from time to time, as I need them. Eventually, I'll release this to PLaneT, but I thought I might ask the community two questions first:
>>>
>>> 1. Am I duplicating the functionality of some library? (If so, I'll just contribute to that instead.)
>>> 2. Do you have any iteration "favorites" that I should include in the library? (Code welcome, but I'm also happy to implement suggestions myself.)
>>>
>>> Alternately, if you guys want to add these to the core, I'd be happy to contribute code and tests....
>>>
>>> Thanks,
>>> Will
>>> _________________________________________________
>>> For list-related administrative tasks:
>>> http://lists.racket-lang.org/listinfo/dev
>>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://lists.racket-lang.org/listinfo/dev
>
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/dev