On Mon, Jul 10, 2017 at 11:02 PM, Nadeem Abdul Hamid <nad...@acm.org> wrote:
> How come this:
>    (for/list ([(x y) (in-parallel '(1 2) '(3 4))]) x)
> produces
>   '(1 2)
> instead of
>   '(1 3)
> ?

You're creating a list of the x values. In the first iteration x is 1,
and in the second it's 2. So the result is '(1 2). You won't see 3 in
the result, because it will be bound to y, not x, in the first
iteration.

> Whereas,
>   (sequence-ref (in-parallel '(1 2) '(3 4)) 0)
> produces
>   1
>   3
> as I would expect, but am I doing something wrong with for/list?


Here, you're getting the first element of the sequence which is (values 1 3).

>
> In general, how might one convert a list of tuples into a multiple-valued
> sequence? i.e. ideally I'd like to be able to just match:
>   (for/list ([(x y) '((1 2) (3 4))])  x)
> and have it produce
>    '(1 3)

I'm not sure exactly what you're looking for, since I can't quite
square your description ("multiple-values sequence") with your example
result -- '(1 3). If that is the result you're looking for, you could
use

  (map first  '((1 2) (3 4)))

If you want to go from  '((1 2) (3 4)) to '((1 3) (2 4)), you could do

  (apply map list '((1 2) (3 4)))

And if you really do want a sequence of multiple values, you could use

  (apply in-parallel '((1 2) (3 4)))

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to