[R] Is = now the same as <- in assigning values

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Dec 19 01:25:59 CET 2008


Stavros Macrakis wrote:
> On Thu, Dec 18, 2008 at 1:37 PM, Wacek Kusnierczyk <
> Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
>
>   
>> Kenn Konstabel wrote:
>>     
>>>> ...foo({x = 2})
>>>>         
>> ...
>>
>> This is legal but doesn't do what you probably expect -- although
>>     
>>> documentation for `<-` says the value (returned by <-) is 'value' i.e.
>>> whatever is on the right side ...
>>>       
>
>   

(just to make clear:  here stavros is answering kenn, not me)

> What do you expect this to do that is different from what it does, namely
> assign 2 to x and call foo on the value 2, which is the same as the value of
> x?  As long as foo doesn't do tricks with substitute, all the following
> should be identical:
>   

<snip>
>
>>> [kenn] If you really hate <-, you should do either
>>> foo({(x=42)})   # or ....
>>>       
>
> Why the () nested within the {} ? Either one alone is enough.
>
>   

these are not identical:

x = 1
(x = 1)


<snip>
>> [vQ] who said = is more intuitive for assignments?  i said i prefer it, and
>> that's because of aesthetics, silly me.  in an earlier post, someone
>> said it is more natural for his students [1].  argue to the contrary.
>>
>> it depends on how you program, mostly.  if you're doing functional
>> programming with no reassignments, = is just perfect.
>>
>>     
>
> The character string denoting assignment really has no deep importance,
> whether it's = (Fortran, C); := (Algol, Pascal, Ada); <- (R); : (Maxima);
> etc.  However, using the same symbol to denote two quite different things
> which can be meaningful in the same contexts, namely assignment and argument
> naming, strikes me as a poor design decision.
>   

as i said, my choice is based on aesthetics, silly me.  i find many
enough poor design decisions in r not be concerned with this superficial
detail.

vQ



More information about the R-help mailing list