[plt-scheme] idiomatic way to split a list into first, middle, last?

From: Dave Herman (dherman at ccs.neu.edu)
Date: Thu Jan 5 20:03:58 EST 2006

> (match l
>   [`(,first ,middle ... ,last)
>     `(,(first-proc first) ,@(map middle-proc middle) ,(last-proc  last))])

If I'm not mistaken, the PLT syntax-rules and syntax-case languages can 
both handle this kind of thing:

     (define-syntax foo
       (syntax-rules ()
         [(_ a b ... c)
          '(a c b ...)]))

     > (foo z x1 x2 x3 y)
     (z y x1 x2 x3)

But I believe the match library does not, as you found out. It's not 
hard to generalize a matching algorithm to handle a fixed number of 
suffixes. Maybe the best thing would be for you to improve the match 
library! :)


Posted on the users mailing list.