[plt-scheme] Possible bug in for/fold
At Fri, 27 Jun 2008 16:20:02 +0100, "Noel Welsh" wrote:
> If for/fold has no accumulators but it does have for-clauses that
> iterate one or more times it gets upset:
>
> -> (for/fold () ([i (in-range 4)]) (vector-set! (vector 0) 0 1))
> context (lexical binding) expected 0 values, received 1 value: #<void>
>
> This is because the body expression (in this case the vector-set!)
> returns a value which for/fold is not expecting. This is kinda
> contrived, but has arisen in the context of a macro I'm writing that
> expands into for/fold (not for/fold/derived yet -- one step at a
> time!)
>
> It could well be argued this is not a bug, but I suggest one of two
> improvements:
>
> 1. for/fold accepts the above case and returns vold
>
> 2. for/fold rejects this case and gives an error at macro expansion time
It's ok to use `for/fold' with zero accumulators as long as the body
produces zero results:
(for/fold () ([i (in-range 4)])
(vector-set! (vector 0) 0 1)
(values))
That seems like the right thing to me. Is there some reason that your
macro can't/shouldn't match the zero accumulators with zero results?
Matthew