From: Mark Adler on
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

From: gekko on
On May 17, 9:12 pm, Mark Adler <mad...(a)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.

From: Albert Retey on
Am 17.05.2010 13:12, schrieb Mark Adler:
> 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?

I don't know...

> 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 think here is a good reason to not do this: What would you expect the
following to return?

{"1", "2"} <> {"3", "4"}

"standard" mathematica evaluates this to a string, your change to
StringJoin changes it to a List, so you might break code that relies on
this behavior...

hth,

albert

From: chris on
look at 'notation' package for possibilities

Mark Adler a =E9crit :
> 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
>
>
>


From: David Bailey on
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?
>
> Mark
>
Well it might make you unwise, though not bad :) I do occasionally
Unprotect built-in symbols, but I always ask myself first if there is an
easier way to achieve the same thing! The general problems associated
with doing this are:

1) The function you modify may get used within other code (including
within other built-in functions) and cause confusion.

2) It is very hard for others to read your code if the built-in
operations don't do what they should.

3) I suspect at least some functions may not behave consistently if
augmented in this way.

String and structural operations are separated in Mathematica, and on
the whole this makes code easier to read because you don't have to ask
yourself if the arguments to StringJoin are meant to be strings or not!

I guess what you really want is an operator to join lists - so why not
overload an otherwise unused binary operator - like
\[ReverseEquilibrium] to perform this task?

BTW, you can always make yourself a palette (or change the Mathematica
menu) of special characters for easy insertion.

David Bailey
http://www.dbaileyconsultancy.co.uk