On Thu, Jul 27, 2017 at 8:36 PM, Robby Findler
<ro...@eecs.northwestern.edu> wrote:
> I see from raco demod that match-define does not generate very
> beautiful code, which leads me to this version (which is what I think
> match-define should have expanded into). It seems to be about 4x
> faster on my computer.

Unfortunately, I don't think `match-define` can avoid the use of
multiple values here. What you're seeing is the difference between:

(define-values (a b) (if (pair? x) (values (car x) (cdr x)) (error 'fail)))


(unless (pair? x) (error 'fail))
(define a (car x))
(define b (cdr x))

`match-define` generates the first snippet, but the second performs
significantly faster. I would like the optimizer to transform the
first into the second, however, since `match-define` has to support
this program:

(match-define (list (cons a b)) ...)

which would expand to:

(define-values (a b) (if (and (pair? x) (null? (cdr x)) (let ([car-x
(car x)]) (if (pair? car-x) (values (car car-x) (cdr car-x)) (error
'fail)) (error 'fail2)))))

which is much harder (although of course not impossible) to transform
into a series of definitions.

`match-define` also has the additional complication that the
identifiers being defined should be in scope in the expression
defining them, which also makes doing this transformation in
`match-define` harder.


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