[plt-scheme] idiomatic way to split a list into first, middle, last?
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