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

Object of confusion

 [1/5] from: SunandaDH::aol::com at: 6-Sep-2004 19:42


Here's a little puzzle that had me delving into the mysteries of sameness and mutability. Maybe you'll enjoy it too: If we make two objects, one based exactly on the other, they look the same: a: make object! [b: 0] c: make a [] probe a make object! [ b: 0 ] probe c make object! [ b: 0 ] So far, so good, Now let's do the same with a self-referential object: a: make object! [b: self] c: make a [] That's perfectly legal, even if it starts to give some odd results, e.g. same? a/b/b/b/b a == true same? c/b/b/b a == true same? c/b/b/b a/b/b/b/b/b/b/b/b/b == true But they don't look the same: probe a make object! [ b: make object! [...] ] probe c make object! [ b: make object! [ b: make object! [...] ] ] Although they do with dump-obj (available in betas): dump-obj a == [" b object! [b] ^/"] dump-obj c == [" b object! [b] ^/"] It confused me. (I'll leave it to the experts to explain what's going on) Sunanda.

 [2/5] from: gabriele::colellachiara::com at: 7-Sep-2004 11:23


Hi Sunanda, On Tuesday, September 7, 2004, 1:42:11 AM, you wrote: Sac> It confused me. (I'll leave it to the experts to explain what's going on) The answer here is pretty simple.
>> a: make object! [b: 0] >> c: make a [] >> same? a c
== false So far, so good, right? C is a clone of A, but they are not the same value. Indeed:
>> a/b: 1
== 1
>> a/b
== 1
>> c/b
== 0 They are not the same, so changing one does not change the other. But now if we do:
>> a/b: a >> c/b: a >> same? a c
== false
>> same? a/b c/b
== true we see of course that A and C are still different values, but A/B and C/B are the same value, because we set them to the same value (A). This accounts for the differences in molding A and C:
>> probe a
make object! [ b: make object! [...] ]
>> probe c
make object! [ b: make object! [ b: make object! [...] ] ] indeed, while A/B refers to A, C/B does not refer to C, but to A. (See above, this is how we set them.) We can represent them as: A ---> [ B ---+ ] ^------+ C ---> [ B ---> [ B ---+ ] ] ^------+ which accounts for the result of MOLD. HTH, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [3/5] from: SunandaDH:aol at: 7-Sep-2004 12:27


Gabriele:
> The answer here is pretty simple.
Thanks....I knew someone could explain it. Here's a related strange thing: b: copy [] load append/only b b Crashes the interpretor (does for all Windows versions I've tried -- and I've bug-track reported it), but b: copy [] load insert/only b b only causes a ** Script Error: Out of range or past end message, unless you try the load a 2nd time: b: copy [] load insert/only b b load insert/only b b then you'll crash the interpretor, Sunanda

 [4/5] from: gabriele::colellachiara::com at: 7-Sep-2004 18:36


Hi SunandaDH, On Tuesday, September 7, 2004, 6:27:25 PM, you wrote: Sac> Here's a related strange thing: Sac> b: copy [] load append/only b b Sac> Crashes the interpretor (does for all Windows versions I've tried -- and I've Sac> bug-track reported it), but Sac> b: copy [] load insert/only b b Sac> only causes a Sac> " ** Script Error: Out of range or past end" message, unless you try the load Sac> a 2nd time: Sac> b: copy [] load insert/only b b load insert/only b b Sac> then you'll crash the interpretor, The difference is that in the first LOAD gets the block at the head, in the second at the tail. Your third version returns to LOAD B at the middle position. About the crash, I guess it's just a failure in handling the infinite recursion... Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [5/5] from: nitsch-lists::netcologne::de at: 7-Sep-2004 14:27


On Dienstag, 7. September 2004 01:42, [SunandaDH--aol--com] wrote:
> Here's a little puzzle that had me delving into the mysteries of sameness > and mutability. Maybe you'll enjoy it too:
<<quoted lines omitted: 20>>
> ] > It confused me. (I'll leave it to the experts to explain what's going on)
Thats a feature!! :) As you said, this works: a/b/b/b/b/b/b/b/b/b . Now think you are mold: You see an object with an object inside with an object inside with an object ... In the old days every such structure leaded to an infinite loop when molded. Terrible while debugging. Then some cool RT-coder added a check for "did i print this?". Then mold prints [...] . instead of going infinite looping.
> Sunanda.
-Volker

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted