From btyner @end|ng |rom gm@||@com  Sat Sep 21 03:03:57 2019
From: btyner @end|ng |rom gm@||@com (Benjamin Tyner)
Date: Fri, 20 Sep 2019 21:03:57 -0400
Subject: [Rd] Should slot<-() alter its first argument?
In-Reply-To: <CAF8bMcan5u+X72Cy2itSbNr=7ovvW7NsZ_q=CX29SfdeOXpmew@mail.gmail.com>
References: <CAF8bMcan5u+X72Cy2itSbNr=7ovvW7NsZ_q=CX29SfdeOXpmew@mail.gmail.com>
Message-ID: <e2c196c2-4709-a379-0bb3-78fa5aec813d@gmail.com>

It appears this started with R version 3.5.0. Under R 3.4.4 we have:

 > setClass("Z", rep=representation(x="character"))
 > z <- new("Z", x="orig")
 > `@<-`(z, "x", value="newer")
An object of class "Z"
Slot "x":
[1] "newer"

 > z
An object of class "Z"
Slot "x":
[1] "newer"

 > `slot<-`(z, "x", value="newest")
An object of class "Z"
Slot "x":
[1] "newest"

 > z
An object of class "Z"
Slot "x":
[1] "newest"


> We noticed that the slot<- function alters its first argument, which goes
> against the grain of a functional language.  The similar @<- does not
> change its first argument.  Is this intended?  The timeSeries and distr
> package depend on this altering.
>
> >/setClass("Z", rep=representation(x="character")) />/z <- new("Z", x="orig") />/`@<-`(z, "x", value="newer") /An object of class "Z"
> Slot "x":
> [1] "newer"
>
> >/z /An object of class "Z"
> Slot "x":
> [1] "orig"
>
> >//>/`slot<-`(z, "x", value="newest") /An object of class "Z"
> Slot "x":
> [1] "newest"
>
> >/z /An object of class "Z"
> Slot "x":
> [1] "newest"
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> 	[[alternative HTML version deleted]]



[Rd] Should slot<-() alter its first argument?
Benjamin Tyner