behavior of =
Fri, 8 Nov 2002 17:56:14 +0100
>Not only would this require rewriting essentially every piece of R code
>ever written, but even worse, := is used in other languages (and in the
>prehistory of R) as an assignment operator so it would be even less clear
>than the current situation.
>For this transition, unlike disposing of '_', there would be no way to
>write code (including simple data analyses) that worked before and after
>You can't get there from here (and I'm not convinced you want to).
Right. But then, may be another (group of) characters could replace '=' for
named argument, eliminating the ambiguity with the assignment. What about
'::' foo(arg::value). In a first stage, '::' could become an alternative to
'=' for named arguments (and during this transition, the problem with
assigment still remains, of course). Then, in the next major release, '=' is
deprecated for named arguments. Finally, another major release later, when
all the code is (hopefully) rewritten with '::' for named arguments, '=' is
defunct for named argument, and '=' gets exactly the same meaning as '<-'
ANYWHERE, eliminating the problem discussed here. As far as I know, '::' is
not used yet in the S language. Some people would say it is replacing a
single character by two (obviously the most lazy ones that objected against
the disparition of '_' for assignation)! Not a major inconvenience, anyway.
Others would say that '::' has a different signification in some other
languages, but then, there is no solution because we have to deal with a
limited character set and a keyboard with only 88-103 keys!
In any case, this is major change, since, whatever the solution, it implies
incompatibles changes in code. I agree! One should note that, if a change
similar to this ('=' replaced by '::' for named arguments) was planned
*before* the introduction of '=' as a (quasi)synonym of '<-' for assignment,
it would have been easier to actualize code in the transitions phases (just
need to protect '==', '<=', '>=', '!=' and occurence of '=' in strings
before replacing any other occurence of '=' by '::'). Now, it would be much,
much more difficult. Compromizes, always compromizes,...
>On Fri, 8 Nov 2002, Philippe Grosjean wrote:
>> Deprecating '_' for assignment in the perspective of reusing it in
>> names is nice (not just a personal impression bacause it is also common
>> other languages). I am fighting too often with unreadable codes like
>> var_value, even without spaces before and after '_'!!!
>> Addition of '=' for assignment is nice too (also commonly used in other
>> languages), except for this problem with named arguments...! I know this
>> a major change that would require patching all R code, but perhaps a
>> solution would be to replace '=' in named arguments with something
>> ('_' for instance.. no, I am kidding!). But perhaps, ':=' would be a
>> candidate. So:
>> foo(a=b) # Assignment of b to a, and a is passed as first argument to
>> function foo()
>> foo(a:=b) # b is passed to the named argument 'a' of function foo()
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: email@example.com