[REBOL] Clone - Object and Hash Cloner
From: al::bri::xtra::co::nz at: 20-Sep-2000 17:44
This is a multi-part message in MIME format.
------=_NextPart_000_02D1_01C0232A.7AE80B00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
I wrote:
> There's a clone function written by Erin, that I'll post to the list soon.
Unfortunately, Erin's clone function didn't work for 'hash!. So here's a
version that does.
[
Rebol [
Title: "Clone"
Name: 'Clone
File: %Clone.r
Version: 1.0.0
Module: 'Clone
Export: [Clone]
Author: "Andrew Martin"
Acknowledgements: "Erin A. Thomas"
Date: 20/September/2000
Purpose: {
Clone objects by copying objects and hashs inside.
}
Example: [
New_object Clone make Original_Object []
]
]
Clone: function [
{Clones all sub-objects and hashes,
so there are no multiple references.}
Object [object!] "The object to clone."
][
Member
][
foreach Word next first Object [
Member: get in Object :Word
if hash? Member [
set in Object :Word copy/deep Member
]
if object? Member [
set in Object :Word Clone make Member []
]
]
Object
]
]
REBOL/View 0.10.33.3.1 10-Sep-2000
Copyright 2000 REBOL Technologies. All rights reserved.
>> do %"/c/windows/desktop/Clone.r"
>> o!: make object! [h: make hash! 10 b: make block! 10]
>> obj: clone make o! []
>> append obj/h 'one
== make hash! [one]
>> append obj/b 'one
== [one]
>> probe obj
make object! [
h: make hash! [one]
b: [one]
]
>> probe o!
make object! [
h: make hash! []
b: []
]
I hope that helps!
Andrew Martin
ICQ: 26227169
http://members.ncbi.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/
-><-
------=_NextPart_000_02D1_01C0232A.7AE80B00
Content-Type: text/x-rebol;
name="Clone.r"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Clone.r"
[
Rebol [
Title: "Clone"
Name: 'Clone
File: %Clone.r
Version: 1.0.0
Module: 'Clone
Export: [Clone]
Author: "Andrew Martin"
Acknowledgements: "Erin A. Thomas"
Date: 20/September/2000
Purpose: {
Clone objects by copying objects and hashs inside.
}
Example: [
New_object Clone make Original_Object []
]
]
Clone: function [
{Clones all sub-objects and hashes,
so there are no multiple references.}
Object [object!] "The object to clone."
][
Member
][
foreach Word next first Object [
Member: get in Object :Word
if hash? Member [
set in Object :Word copy/deep Member
]
if object? Member [
set in Object :Word Clone make Member []
]
]
Object
]
]
------=_NextPart_000_02D1_01C0232A.7AE80B00--