From csardi.gabor at gmail.com  Wed Jun 17 15:19:42 2015
From: csardi.gabor at gmail.com (=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=)
Date: Wed, 17 Jun 2015 09:19:42 -0400
Subject: [Rd] Improving string concatenation
In-Reply-To: <CAOQ5Nyf+cLHEtRzC-ZJ=bdL7GKgznzhQ2-pb4BjyfAJafdVzbg@mail.gmail.com>
References: <CAKShX4A5bVtxVAG+01QjNH0=LaVr6MH48xXs-OtbQQ2247cc_g@mail.gmail.com>
	<5580BE4F.8060401@fredhutch.org>
	<CABtg=KmfPxZsW7Bfn8EALQb5aT03cMXt0sDzam=ECmhUydb=Sw@mail.gmail.com>
	<CAKShX4DCwKwuq7Q7hBFkMebPAkc=4SU=LWq+gEEHeFT35XuhFQ@mail.gmail.com>
	<CAOQ5Nyf+cLHEtRzC-ZJ=bdL7GKgznzhQ2-pb4BjyfAJafdVzbg@mail.gmail.com>
Message-ID: <CABtg=KkYPtwV4PvET=dnGRdsppc6DU+GzcgL5fPtapok8u9YTA@mail.gmail.com>

On Wed, Jun 17, 2015 at 9:04 AM, Michael Lawrence
<lawrence.michael at gene.com> wrote:
> Just to clarify, primitive (C-level) generics do not support dispatch
> on basic classes (like character). This is for performance (no need to
> consider dispatch on non-objects) and for sanity (in general,
> redefining fundamental behaviors is dangerous). It is of course
> possible to define a "+" method with a signature containing a class
> not in the set of basic classes.

I see, thanks for pointing this out.

Still, I see this as a technicality. The current "+" clearly detects
if it gets a non-numeric argument, because it gives an error message
for it. So in this case it could just check if both sides are
characters, and if that's true, concatenate them. So there is no
performance loss at all.

This is obviously not as clean as a dispatch, but I think it is still
better than requiring people to add classes to their strings,
especially if the strings are literals.

Btw. for some motivation, here is a (surely incomplete) list of
languages with '+' as the string concatenation operator:

ALGOL 68, BASIC, C++, C#, Cobra, Pascal, Object Pascal, Eiffel, Go,
JavaScript, Java, Python, Turing, Ruby, Windows PowerShell,
Objective-C, F#, Scala, Ya.

and there are a lot of others that have a different operator for it:

Haskell, Erlang, Ada, AppleScript, COBOL (for literals only), Curl,
Seed7, VHDL, Visual Basic, Excel, FreeBASIC, Perl, PHP, Maple, Icon,
Standard SQL, PL/I, Rexx, Mathematica, Lua, Smalltalk, OCaml, Standard
ML, F#, rc, Fortran.

Source: https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(strings)

Yes, even Fortran has one, and in C, I can simply write "literal1"
"literal2" and they'll be concatenated. It is only for literals, but
still very useful.

Best,
Gabor



[Rd] Improving string concatenation
=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=