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

From: Bill Wood (william.wood3 at comcast.net)
Date: Thu Jan 5 23:19:14 EST 2006

On Thu, 2006-01-05 at 16:20 -0800, John Clements wrote:
> Here's what I want:
> 
> (match l
>    [`(,first ,middle ... ,last)
>      `(,(first-proc first) ,@(map middle-proc middle) ,(last-proc  
> last))])

It occurred to me that this is actually pretty easily expressed in
Prolog.  The text

    trisect( List, First, Middle, Last ) :-
        append( [First], Xs, List ),
        append( Middle, [Last], Xs ).

defines the relation "trisect" which splits the argument List into the
element First, the list Middle and the element Last.

My question is, has anyone considered a match function that supported
pattern variables that act more like Prolog logical variables?

 -- Bill Wood




Posted on the users mailing list.