`in-dict` can get you mostly there.
(for ([(i j) (in-dict '(("a" 1) ("b" 20)))])
(display (list i j)))
> (a (1))(b (20))
If you have lists of pairs instead of lists of lists, you'll get the
same result as the hash case.
Vincent
On Wed, 21 Nov 2018 10:55:23 -0600,
Brian Adkins wrote:
>
> I thought it was possible to destructure a list in for, but I've been
> searching/experimenting for a while without success. I noticed this example
> in the docs:
>
> (for ([(i j) #hash(("a" . 1) ("b" . 20))])
> (display (list i j)))
>
> So, I assumed I could do this:
>
> (for ([(i j) '(("a" 1) ("b" 20))])
> (display (list i j)))
>
> But that doesn't work. I'm trying to avoid something as verbose as:
>
> (for ([(pair) '(("a" 1) ("b" 20))])
> (match-let ([(list i j) pair])
> (display (list i j))))
>
> Why do elements of a Hash provide 2 values to for, where a 2-tuple list does
> not? Is there a more direct way to destructure a list in for?
>
> Thanks,
> Brian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.