[plt-scheme] ML pattern programming macro in scheme

From: Felix Klock's PLT scheme proxy (pltscheme at pnkfx.org)
Date: Wed Mar 3 19:39:12 EST 2004

On Mar 3, 2004, at 7:29 PM, Felix Klock's PLT scheme proxy wrote:
> Here are the first three of your examples, written with the 
> MATCH-LAMBDA special form, which is part of the standard match.ss 
> library.
>
> (require (lib "match.ss"))
>
> (define lengthvec (match-lambda [(x y) (sqrt (+ (* x x) (* y y)))]))
> (define addvec    (match-lambda [((x1 y1) (x2 y2)) (list (+ x1 x2) (+ 
> y1 y2))]))
> (define negvec    (match-lambda [(x y) (list (- x) (- y))]))
>

Whoops.

You need to use the MATCH-LAMBDA* special form for the ADDVEC 
implementation; MATCH-LAMBDA (no star) only defines a single argument 
function.

Serves me right for posting code instead of just pointing to the 
reference...

-Felix

----
"They only reproduce when they interact. That's
  like men and women, kind of."  -G.C. Rota (11/26/97)



Posted on the users mailing list.