[REBOL] NOT a bug - Bug! - 'second ... Re:(2)
From: al:bri:xtra at: 6-Oct-2000 0:15
Everyone is right in saying this is not a bug! I agree too!
> >> print mold second o
> [
> make object! [
> a: "fee"
> b: "fie"
> c: "foe"
> d: "fum"
> ] "fee" "fie" "foe" "fum"]
The first thing in:
second o
is the 'self word, which points to the object itself. That's this part:
make object! [
> a: "fee"
> b: "fie"
> c: "foe"
> d: "fum"
> ]
The values of o/a, o/b, o/c and o/d are the next four things in second
o:
"fee" "fie" "foe" "fum"
I thought it was a bug, because I have never before looked at what second
returns from an object and because at the time, I was writing a object
cloner which automatically copies an object, without having to have special
code for the hash! data type. Here's what I've got for this:
[
Rebol [
Name: 'Clone
Title: "Clone"
File: %Clone.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 6/October/2000
Enhancement: 'Clone
Acknowledgements: "Erin A. Thomas"
Purpose: {
Clone objects by copying objects inside.
}
Example: [
New_object Clone Original_Object []
]
]
Clone: function [[catch]
{Clones all sub-objects and hashes, so there are no multiple
references.}
Object [object!] "The object to clone."
Block [block!] "Extra code for this object."
][
Cloned Member
][
Cloned: make Object Block
foreach Word next first Object [
Member: get in Cloned :Word
if same? Member get in Object :Word [
set in Cloned :Word either object? Member [
Clone Member []
][
either any [
series? Member
port? Member
bitset? Member
][
copy/deep Member
][
Member
]
]
]
]
Cloned
]
]
When I was checking the cloned objects, I thought something had gone
hideously wrong with my 'Clone function.
Thanks everyone for pointing it out!
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/