There is a "generic" `sequence-map`.

But it's not variadic like `map` -- and like you want in your example.

You could try writing a variadic `sequence-map`?

As for `for/list`, you _could_ write:

(for/list ([a as]
           [b bs]
           [n (in-naturals)])
  (foo a b n))

It's faster if you supply `in-list` for `as` and `bs`, as did David.
When you do, it expands to code that's about as fast as if you wrote
it by hand.  But if you know the list will have only a few items, and
it doesn't matter, you could omit `in-list`. Granted it's still more
verbose than `map` style.

Speaking of writing by hand, you could use `match*` to remove some
car/cdr textbook tedium -- but it's still fairly tedious:

(let loop ([as as] [bs bs] [n 1])  ;`in-naturals` is 1.. -- use 0 here
if you prefer
  (match* [as bs]
    [[(cons a as) (cons b bs)] (cons (foo a b n)
                                     (loop as bs (add1 n)))]
    [[_ _]                     '()]))

I think one theme here is a trade-off between abstraction and speed
Another is a trade-off between functions and macros. Macros like `for`
and `match` can expand into efficient code that you wouldn't want to
write by hand.

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 
For more options, visit

Reply via email to