From murdoch@dunc@n @end|ng |rom gm@||@com  Mon Dec  6 11:06:42 2021
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Mon, 6 Dec 2021 05:06:42 -0500
Subject: [Rd] string concatenation operator (revisited)
In-Reply-To: <20211206061402.GA3810@mail.cs.toronto.edu>
References: <mailman.52192.3.1638702001.27673.r-devel@r-project.org>
 <20211206061402.GA3810@mail.cs.toronto.edu>
Message-ID: <b3509a16-a132-8a4e-322f-ccb708d12ff1@gmail.com>

On 06/12/2021 1:14 a.m., Radford Neal wrote:
>> The TL;DR version is base R support for a `+.character` method. This
>> would essentially provide a shortcut to `paste0`...
> 
> In pqR (see pqR-project.org), I have implemented ! and !! as binary
> string concatenation operators, equivalent to paste0 and paste,
> respectively.
> 
> For instance,
> 
>      > "hello" ! "world"
>      [1] "helloworld"
>      > "hello" !! "world"
>      [1] "hello world"
>      > "hello" !! 1:4
>      [1] "hello 1" "hello 2" "hello 3" "hello 4"

I'm curious about the details:

Would `1 ! 2` convert both to strings?

Where does the binary ! fit in the operator priority?  E.g. how is

   a ! b > c

parsed?

Duncan Murdoch


>      
> This seems preferable to overloading the + operator, which would lead
> to people reading code wondering whether a+b is doing an addition or a
> string concatenation.  There are very few circumstances in which one
> would want to write code where a+b might be either of these.  So it's
> better to make clear what is going on by having a different operator
> for string concatenation.
> 
> Plus ! and !! semm natural for representing paste0 and paste, whereas
> using ++ for paste (with + for paste0) would look rather strange.
> 
>     Radford Neal
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] string concatenation operator (revisited)
Duncan Murdoch