[Rd] capture "->"

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sat Mar 2 12:31:38 CET 2024


You can't change the parser.  Changes like `+` <- `-` change the 
function that is called when the expression contains a function call to 
`+`; this happens in `eval()`, not in `parse()`.  There are never any 
function calls to `->`, because the parser outputs a call to `<-` with 
the operands reversed when it sees that token.

Duncan Murdoch

On 02/03/2024 6:06 a.m., Adrian Dușa wrote:
> That would have been an elegant solution, but it doesn't seem to work:
> 
>> `->` <- `+`
>> 1 -> 3 # expecting 4
> Error in 3 <- 1 : invalid (do_set) left-hand side to assignment
> 
> It is possible to reassign other multiple character operators:
>> `%%` <- `+`
>> 1 %% 3
> [1] 4
> 
> The assignment operator `->` is so special for the R parser, that it seems
> impossible to change.
> 
> On Fri, Mar 1, 2024 at 11:30 PM <avi.e.gross using gmail.com> wrote:
> 
>> Adrian,
>>
>> That is indeed a specialized need albeit not necessarily one that cannot
>> be done by requiring an alternate way of typing a formula that avoids being
>> something the parser sees as needed to do at that level.
>>
>> In this case, my other questions become moot as I assume the global
>> assignment operator and somethings like assign(“xyz”, 5) will not be in the
>> way.
>>
>> What I was wondering about is what happens if you temporarily disable the
>> meaning of the assignment operator <- and turn it back on after.
>>
>> In the following code, for no reason, I redefine + to mean – and then undo
>> it:
>>
>>
>>> temp <- `+`
>>> `+` <- `-`
>>> 5 + 3
>> [1] 2
>>> `+` <- temp
>>> 5 + 3
>> [1] 8
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list