Re: copying objects
Eric DeWitt <[email protected]>
| Newsgroups | gmane.comp.breve |
|---|---|
| Message-ID | <[email protected]> |
I believe this code will act as you'd expect--that is you'd get new
references to the same objects, not new objects. In most OO languages,
object copies are not directly availible, unless they are specifically
implemented by a method (e.g. foo.getCopy()) because there is ambiguity
as to what a copy would be (shallow or deep, etc.). You will need to
do something like the following:
Object: MyObject {
+ to get-copy:
return (new MyObject) init-with what ever parameters I need to pass
to get the copy I want.
}
then you can iterate over the list and assign 'newObject = (oldObject
get-copy).' and push it onto the list.
-e
On Tuesday, March 2, 2004, at 03:01 PM, Will Davis wrote:
> Raphael Crawford-Marks wrote:
>
>> Is there an easy way to copy objects?
>>
>> I need to copy a list of objects, and copylist only gives me a new
>> list with the
>> same objects. Do I need to create a custom method for this, or is
>> there a
>> built-in way of doing it?
>>
>> Thanks,
>>
>> Raphael
>>
>>
>>
> list (list).
> newlist (list).
> item (object).
> newitem (object).
>
> foreach item in list: {
> newitem = item.
> push newitem onto newlist.
> }
>
> Dunno if there's a custom list-copy method, but the code above should
> do it.
>
Eric DeWitt
[email protected]
School of Cognitive Science
Hampshire College
_______________________________________________
breve mailing list
[email protected]
http://www.spiderland.org/mailman/listinfo/breve