[racket] Combining iteration and match

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Wed Sep 4 02:49:48 EDT 2013

Konrad Hinsen writes:

 > a struct. Is there a more compact way to do this? Ideally I'd like
 > to write
 > 
 >   (for/list ([(list a b) some-sequence])
 >     a)

Thanks to all who replied. In summary, there are two options:

1) match-define

  (for/list ([a+b some-sequence])
    (match-define (list a b) a+b)
    a)

2) generic-bind

  (~for/list ([$((list a b)) some-sequence])
    a)

I much prefer 2) because it avoids to introduce an explicit temporary
variable. For my current experiments I can afford to be a guinea-pig
for code under development, so I will adopt generic-bind and see how
far I get.

There is just one point I'd like to understand better:

Stephen Chang writes:

 > Like others have mentioned, my generic-bind package has the
 > functionality you want but is still in the experimental stages. For
 > small programs, the generic-bind for/_ forms are about as fast as the
 > current Racket implementation but expect 2-3x slowdown for larger
 > programs.

Since the criterion seems to be the size of the program, do I conclude
correctly that the slowdown concerns compile-time, rather than run-time?
If not, what aspect of program size matters?

Konrad.

Posted on the users mailing list.