Re: Overloading StringJoin
- To: mathgroup at smc.vnet.net
- Subject: [mg109819] Re: Overloading StringJoin
- From: Mark Adler <madler at alumni.caltech.edu>
- Date: Wed, 19 May 2010 07:02:20 -0400 (EDT)
- References: <hsr8al$bev$1@smc.vnet.net> <hstadv$e3i$1@smc.vnet.net>
Thank you all for your replies.
On 2010-05-17 23:00:31 -0700, gekko said:
> On May 17, 9:12 pm, Mark Adler <mad... at alumni.caltech.edu> wrote:
>> Unprotect[StringJoin];
>> x_List <> y_List := x~Join~y
>> Protect[StringJoin];
> This may work fine for your current needs, but what happens when you
> actually need the StringJoin function?
Well, obviously I wrote so that I can still use <> to join strings.
This still works:
"ab" <> "cd"
abcd
However as pointed out by Albert Retey, it breaks the flat behavior of
<> where normally this:
{{"a", "b"}, "c"} <> {"d", {"e", {"f", "g"}}}
produces the single string:
abcdefg
whereas with my violation of StringJoin it returns:
{{a, b}, c, d, {e, {f, g}}}
That's enough reason for me to not do it, since something else may
depend on that.
Too bad. <> looks good for a join function and is easy to type.
Chris pointed out the Notation package. I hadn't noticed that before.
(I probably haven't noticed about 90% of what Mathematica can do.) So
now I can do something like:
<< Notation`
InfixNotation[NotationTemplateTag[**], Join]
{1, 2} ** {3, 4}
{1, 2, 3, 4}
I'm sure that there's something wrong with using ** as well, but anyway
you get the idea. I can make up my own symbol.
Mark