Re: Overloading StringJoin
- To: mathgroup at smc.vnet.net
- Subject: [mg109790] Re: Overloading StringJoin
- From: gekko <pfalloon at gmail.com>
- Date: Tue, 18 May 2010 02:00:36 -0400 (EDT)
- References: <hsr8al$bev$1@smc.vnet.net>
On May 17, 9:12 pm, Mark Adler <mad... at alumni.caltech.edu> wrote: > I use Join enough that I like to overload StringJoin to do it: > > Unprotect[StringJoin]; > x_List <> y_List := x~Join~y > Protect[StringJoin]; > > Then I can do this: > > {1, 2} <> {3, 4} > {1, 2, 3, 4} > > Why doesn't Mathematica already do this? It seem like an obvious use > of <>. Or is there a good reason that they don't do this, and > therefore if I do, it makes me a bad person? > > Mark This may work fine for your current needs, but what happens when you actually need the StringJoin function? A more robust solution would be to co-opt one of the infix operators that doesn't already do something. e.g. In[115]:= CirclePlus[lists__List] := Join[lists] In[116]:= {1,2,3}\[CirclePlus]{4,5,6} Out[116]= {1,2,3,4,5,6} Check out the section "Operators without Built-in Meanings" in the built-in help for other possibilities. Cheers, P.