dup, clone, and "deep copy" 
Author Message
 dup, clone, and "deep copy"

I see that Object#dup creates a new object and copies its instance
variables (no deep copy).  Object#clone creates a new object but much
more state is retained (singleton methods, I'm not sure what else).

In sub classes, are there any conventions for how deep a copy dup and
clone should make?  Say I have a class:

    class Foo
        def initialize


        end

        private
        def dup_self


            self
        end
    end

I assume that these are reasonable?

    class Foo
        def dup
            temp = super
            temp.dup_self
        end
        def clone
            temp = super
            temp.dup_self
        end
        def deep_dup
            Marshall::load(Marshall::dump(dup))
        end
        def deep_clone
            Marshall::load(Marshall::dump(self))
        end
    end

--
matt



Tue, 29 Jun 2004 06:28:01 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Making a "deep" copy

2. Deep Magic: "Uncommon Lisp"

3. Deep Magic: "Uncommon Lisp"

4. Developing "Quicken" clone -- advice wanted

5. Q: "deep" Tcl_DuplicateObj()

6. Deep Magic: "Uncommon Lisp"

7. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

8. A hack for "list-copy"

9. newbie:copy"strecke"

10. COPY "QPR.CPY"

11. Coding for "copy on write"

12. Button for "copy"?

 

 
Powered by phpBB® Forum Software