From: Szabolcs Horvát on 5 Dec 2009 05:34 On 2009.12.04. 10:32, Jezzybear wrote: > I am trying to create a function myflat[list] to mimic the behavior of > Mathematica's Flatten[] > function.Example: > In[1]:= myflat[{{{a}}, {b, c}, {d}}] > Out[1]= {a, b, c, d} > In[2]:= myflat[{{}, 1, {{2}}}] > Out[2]= {1, 2} > However in writing this function I want to use only Mathematica's > pattern matching features, the functions > First[], Rest[], Prepend[], ListQ[]. I am trying to do this using some > subfunctions like creating one called myjoin > > How about something like flatten[list_List] := list //. {s___, {i___}, e___} :> {s, i, e} flatten[{{1, 2}, {3, {4, 5}}}]
From: Norbert Marxer on 5 Dec 2009 05:38 On Dec 4, 10:32 am, Jezzybear <jezzybea...(a)hotmail.co.uk> wrote: > I am trying to create a function myflat[list] to mimic the behavior of > Mathematica's Flatten[] > function.Example: > In[1]:= myflat[{{{a}}, {b, c}, {d}}] > Out[1]= {a, b, c, d} > In[2]:= myflat[{{}, 1, {{2}}}] > Out[2]= {1, 2} > However in writing this function I want to use only Mathematica's > pattern matching features, the functions > First[], Rest[], Prepend[], ListQ[]. I am trying to do this using some > subfunctions like creating one called myjoin Hello You mean pattern matching like: myflat[x_] := {x //. List -> Sequence} Best Regards Norbert Marxer
First
|
Prev
|
Pages: 1 2 Prev: Manipulate jitter Next: ** DECEMBER DISCOUNT: A WorkLife FrameWork.... |