Re: Flatten alternative
- To: mathgroup at smc.vnet.net
- Subject: [mg105500] Re: [mg105469] Flatten alternative
- From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
- Date: Sat, 5 Dec 2009 05:34:17 -0500 (EST)
- References: <200912040931.EAA06957@smc.vnet.net>
A solution using ReplaceRepeated (//.): In[1]:= rule = {pre___, L_List, post___} :> {pre, Sequence @@ L, post}; In[2]:= {{{a}}, {b, c}, {d}} //. rule Out[2]= {a, b, c, d} In[3]:= {{}, 1, {{2}}} //. rule Out[3]= {1, 2} Adriano Pascoletti 2009/12/4 Jezzybear <jezzybear19 at hotmail.co.uk> > 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 > > >
- References:
- Flatten alternative
- From: Jezzybear <jezzybear19@hotmail.co.uk>
- Flatten alternative