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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Jan 5 23:44:24 EST 2006

On Jan 5, 2006, at 11:19 PM, Bill Wood wrote:

> 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 ) :-

You got the constructor wrong here. This wouldn't do it.

>         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?

See Schelog. -- Matthias


>
>  -- Bill Wood
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.