[plt-scheme] Re: idiomatic way to split a list into first, middle, last?
I think the Mathematica language has a (non linear !) pattern-
matching very interesting :
(* defining function split, notice 1 underscore for element pattern
x_ and y_
and 2 underscores for segment pattern y__ *)
split[{x_, y__, z_}] := {x, z}
(* using split *)
In[8]:= split[{a, b, c, d, e, f}]
Out[8]= {a, f}
(* defining function find to get the list after the second occurence
of x *)
find[{x_, y__, x_, z__}] := z
(* using find *)
In[10]:= find[{a, b, c, d, a, e, f, g}]
Out[10]= Sequence[e, f, g]
Alas, no interpreter source of the Mma language is available (except
some hack by Richard Fateman in Lisp I think)...
Such a match functionality in DrScheme could maybe even improve over
ML matching ?
-jpr