From: Bill Rowe on
On 5/17/10 at 7:12 AM, madler(a)alumni.caltech.edu (Mark Adler) 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?

I've no idea why this functionality isn't built-in nor does it
make you a bad person to overload StringJoin this way. But,
there is some level of risk in overloading built-in functions of
Mathematica. There maybe unwanted side effects. So, I would use
one of the built-in operators which do not have any defined
functionality instead of <>. For example, there is CirclePlus
which can be entered as esc c + esc. This would ensure there is
no possibility of unwanted side effects.


From: Mark Adler on
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...(a)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

From: Bill Rowe on
On 5/19/10 at 7:02 AM, madler(a)alumni.caltech.edu (Mark Adler) wrote:


>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.

Yes, ** already has a built-in meaning See ref/NonCommutativeMultiply

>I can make up my own symbol.

If you start with some symbol the first thing you should do is
check to see if what you want to use already has a meaning in
Mathematica by looking it up in the Documentation Center. But
you can avoid conflicts and using the Notation package by simply
selecting one of the symbols Mathematica knows about but that
have no pre-defined meaning such as CirclePlus.

See tutorial/OtherMathematicalNotation for a list of operators
Mathematica knows but do not have pre-defined meaning.

Other references that relevant to this are:

tutorial/Operators and
tutorial/InputAndOutputInNotebooksOverview


From: Mark Adler on
On 2010-05-20 03:40:26 -0700, Bill Rowe said:
> Yes, ** already has a built-in meaning See ref/NonCommutativeMultiply

I did already know that, but I also knew that ** doesn't actually do
anything! Furthermore, joining lists is non-commutative.

I don't like circle-plus aesthetically, which people keep suggesting.
I will be using a compound symbol, maybe **, but probably not.

Mark