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/
-><-
[
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
	]

]

Reply via email to