Re: [S] Assignment arrow.

Scott.Chasalow@USERS.PV.WAU.NL
Tue, 26 May 1998 10:37:05 -0200


On Thu May 21 19:41:15 1998,
Z. Todd Taylor <Todd.Taylor@pnl.gov> wrote:
>Don MacQueen <macqueen1@llnl.gov> wrote:
>
>> Splus has a variety of syntax options that are useful, but that I tend to
>> avoid for the sake of clarity and quick comprehension. For example,
>> embedded assignment:
>> if ( x.cls <- inherits(x,'lm') ) {...}
>> (admittedly, this one isn't really all that bad, but you get the idea, I
hope)
>
>I love that particular idiom (as well as others like it)...

After having been bitten once, this particular idiom is one I never ever use
anymore. OK, in an if (...) statement its no problem. But used in the
argument
list of a function call it can be. Why? Lazy evaluation. Watch:

> danger <-
function(x, y)
{
if(x < 0)
x
else y
}

> danger(-1, a <- 2)
[1] -1

> a
Error: Object "a" not found

> danger(1, a <- 2)
[1] 2

> a
[1] 2

Whether or not object "a" is created depends on the value of argument x.
Not particularly nice. Of course this is a simplified example where the
result
is pretty obvious; it can get much more obscure.

As for the "_" assignment operator, I use it all the time at the command line
(lazy fingers), never ever when writing functions. I'm (= I am) not sure what
the fuss is about, except perhaps aesthetics. Been working with S this way
for years now and I'm still functioning reasonably well...

Groeten,
Scott

P.S. Bill, I'm working on that formatting. ;)
====================================
Scott.Chasalow@users.pv.wau.nl

Wageningen Agricultural University
Laboratory of Plant Breeding
P.O. Box 386
6700 AJ Wageningen
THE NETHERLANDS

http://www.spg.wau.nl/pv/staff/Chasal_S.htm
=====================================

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news