[racket] Named let and multiple values

From: Diogo F. S. Ramos (diogofsr at gmail.com)
Date: Thu Jul 28 00:37:23 EDT 2011

Justin Zamora <justin at zamora.com> writes:

> I'd like to be able to write something like this:
> (let loop ([a 1] [b 2])
>    (if (= a b)
>       3
>       (loop (values (add1 a) b))))
> This would match the way for/fold works with more than one value.
> However, I get a message, "context expected 1 value, received 2
> values: 2 2", which makes sense given the expansion of named let, but
> it would be nice if this worked.  Using (call-with-values (lambda ()
> (values (add1 a) b)) loop) works, but that seems to defeat the point
> of using a named-let form for clarity.  I could also use let-values to
> deconstruct the values and pass them individually to the loop, but
> that hardly seems better.  Is there a better way?

Maybe I didn't understand the purpose of it, but why are you using

Would this do what you want?

(let loop ([a 1] [b 2])
  (if (= a b)
      (loop (add1 a) b)))

Diogo F. S. Ramos

Posted on the users mailing list.