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

[REBOL] Re: On mutability and sameness

From: joel:neely:fedex at: 13-Jun-2001 0:16

Hi, Ladislav, Ladislav Mecir wrote:
> Hi, > > a: now ; == 6-Jun-2001/22:36:26+2:00 > b: a ; == 6-Jun-2001/22:36:26+2:00 > same? a b ; == true > a/day: 7 ; == 7 > same? a b ; == false > > provides evidence that the value of 'a has been replaced > instead of mutated. >
Or else it simply provides evidence that DATE! values are not sharable (i.e., DATE! is not a reference type)! This seems to be at the root of your desire to call DATE! and TIME! values immutable. I believe the following model to be simpler: 1) For reference types, the datum associated with a word (the value to which it is "set") is a reference to the data value, not a copy of the data itself. This means that multiple words can "name" or "share" the same referenced data. 2) For simple/scalar/direct/small/nonreference data types, the datum associated with a word is a copy of the data value itself. This means that values of these types cannot be "shared" in the same way as reference types. (However, if these data values are located within more complex data structures which themselves are shared, then it becomes possible to traverse alternate paths which arrive at the same nonreference value. In such cases, a modification to the value (if it is mutable) will be visible through all such "computed" references.) For example, in:
>> b: []
== []
>> insert b now
== []
>> a: reduce ['then "whatever" 'jetzt b]
== [then "whatever" jetzt [13-Jun-2001/0:08:19-5:00]]
>> o: make object! [x: 42 y: copy a] >> o/y/jetzt/1/month: 7
== 7
>> b
== [13-Jul-2001/0:08:19-5:00] the simplest explanation is that the MONTH field of a DATE! value was changed. I know of no motivation for making it any more complicated than that. But, "What about SAME?", one might ask. If SAME? is implemented simply by comparing one "datum" with another "datum", then: 1) for reference types, SAME? tests whether the two values (reference!) refer to a common, shared data structure, but 2) for simple/scalar/direct/small data types, SAME? only tests whether the two values are currently equal. Simple. -jn- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com