Skip to content

Is there any difference between <- and =

3 messages · Alan Zaslavsky, Wacek Kusnierczyk

#
I would argue that this is a matter of preference and the arguments on 
"principle" for one side or another are not particularly compelling. 
When the "=" was introduced for assignment, an argument was made that 
name=value function arguments are also implicitly a kind of assignment. 
While Duncan has pointed out a typical example of how this could be 
ambiguous, <- also has its problems.  A syntactic confusion with "<-" 
arises in expressions like

 	x<-3

which could be read either as an assignment or as a logical expression 
comparing x to -3.  Perhaps obviously ambiguous when written naked like 
this but when buried in a larger expression, it's easy to write an 
expression like that and discover that you have overwritten x.  Some might 
(and have, most emphatically) advise that we should routinely insert 
spaces in our typing in a way that disambiguates such expressions but I 
find an argument that relies on spaces, which are usually syntactically 
unmeaningful, not very compelling.

Besides, I just find that clumsy two-character arrow ugly!  This is an 
esthetic matter -- reminds me too much of an emoticon. :-( For over 10 
years I used the alternative "_" underscore for S assignment (nice as a 
single character with no competing syntactic meaning) but that has gone 
away, as far as I can tell primarily due to discomfort (disdain?) of 
developers who find it unattractive because of the use of "_" as a 
connecting special category in OTHER contexts (C and shell programming).

However, a mutually satisfactory solution is at hand!!  If growth in the 
number of R programmers continues exponentially at its current rate, by 
the year 2097 the number of R programmers will exceed the population of 
the earth.  At that point they will rise up and demand the restoration of 
the APL arrow key (remembered by some doddering guru who heard about it 
from her grandfather) to the standard keyboard, and our problem will be 
solved.  (But there will be a minor irritation because in the New Zealand 
keyboard that key code will have been assigned to the locally popular 
sheep icon.)

 	Alan Zaslavsky
#
Alan Zaslavsky wrote:
indeed;  i have argued (i think...) for treating them as equals, the
vhoice being a matter of taste.
sure they are.  you assign (or not, depending on whether the arguments
are actually used) to function-call-local variables, that is, the
function's parameters.
ha!  cool.
even worse if the code is processed in some way that might remove
spaces, thus turning < - into <-.
:)
by that time r programs will be scanned directly from your head, i
suppose, and the intelligent scanner will as gladly take <- as it will
=, so the problem will rather vanish.

vQ
#
thanks for your supportive comments!

by that time r programs will be scanned directly from your head, i
suppose, and the intelligent scanner will as gladly take <- as it will
=, so the problem will rather vanish.

Yes, and maybe the scanner will be more intelligent than the programmer so 
when the programmer is confused about what he/she wants, the scanner will 
figure it out!  :-)