Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: On mutability and sameness

From: lmecir:mbox:vol:cz at: 6-Jun-2001 19:31

Hi Joel, ...snip...
> > I am pretty sure, that the feature you are describing is not > > a bug. The reason for the behaviour is pretty simple. Rebol > > values of type TUPLE! DATE! INTEGER! and some other types > > are immutable ... > > > > Part of my point was that the above assertion is no longer > strictly true (I believe there's been a change at some point), > at least with regard to DATE! values. Comparing > > >> a: make date! [2001 6 6] == 6-Jun-2001 > >> a/day: 7 == 7 > >> a == 7-Jun-2001 > > with > > >> a: make object! [x: 17 y: 42 show: does [print [x y]]] > >> a/show 17 42 > >> a/x: 19 == 19 > >> a/show 19 42 > > it seems reasonable to conclude that the first transcript > demonstrates changing a component of a date "in place", which > would mean that DATE! values *are* mutable. However, > > >> a: make date! [2001 6 6] == 6-Jun-2001 > >> b: a == 6-Jun-2001 > >> a/day: 7 == 7 > >> a == 7-Jun-2001 > >> b == 6-Jun-2001 > > provides evidence that DATE! is not a "reference" type.
...snip...
> Here our interpretations differ. By analogy with > > >> a: make object! [x: 17 y: 42 show: does [print [x y]]] > >> a/show 17 42 > >> a/x: 19 == 19 > >> a/show 19 42 > > and with > > >> a: [x 6 y 7 z 42] == [x 6 y 7 z 42] > >> a/x == 6 > >> a/x: 9 == [x 9 y 7 z 42] > >> a == [x 9 y 7 z 42] > > it seems reasonable to understand a SET-PATH! as mutation; it > seems to change an element of a composite structure "in place", > rather than computing and returning a modified copy of the > entire structure.
...snip... I see, that the only reason why you think, that set-path is a DATE! mutation instrument is the analogy with the behaviour of set-path for objects. I have a different POV, because I know, that the behaviour of set-path for objects nor is analogical to the set-path behaviour for DATE! type values, neither it was analogical before. That is why I used a different instrument - my own definition of mutability/immutability for values, a definition helping me to find out whether a value has/ hasn't been mutated/altered or not. Here it is: Let's have a Rebol function F and a DATE! value VALUE. I tell, that F can mutate i.e. alter VALUE, if the following expression yields true: do function [ {does F alter VALUE?} f [any-function!] value [date!] ] [camera picture] [ camera: func [value [date!]] [ reduce [ type? value value/1 value/2 value/3 value/4 value/5 ] ] picture: camera value (f value) not equal? picture camera value ] :f :value Moreover, I call a DATE! value immutable, if there isn't a function F able to mutate it. In this sense all DATE! values are immutable. Just an illustration: f: func [value [date!]] [ either value/1 = 2000 [ value/1: 2001 ] [value/2: 2000] ] value: now the result we get is: == false Does this make sense to you? Regards Ladislav