[REBOL] Object of confusion
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.