[plt-scheme] Possible bug in for/fold

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri Jun 27 11:22:35 EDT 2008

It looks like you want for, not for/fold.

On Fri, Jun 27, 2008 at 11:20 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> Hello,
> 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

Carl Eastlund

Posted on the users mailing list.