From: Joe Keane
Subject: Re: Problems Copying Structures
Date: 
Message-ID: <4083@osc.COM>
In article <·····················@Think.COM> ······@think.com (Barry Margolin)
writes:
>Structure copiers are only supposed to copy the structure itself, not the
>objects referenced by the structure.  They are like COPY-LIST rather than
>COPY-TREE.  If you want more, you have to write your own copier function
>that does precisely what you want.  There's no standard function that's
>able to read the programmer's mind and determine which parts of a structure
>should be copied and which should just be referenced.

>Note that this [structure copier] still only copies one level more
>than the automatically-generated copier.  If you also want to copy
>the objects referenced in the arrays you'll have to do more.

In article <·····@aerospace.AERO.ORG> ···@aerospace.aero.org (Scott "TCB"
Turner) writes:
>One of the better arguments for object-oriented programming.

I don't see what object-oriented programming has to do with this.  The same
problems with deep vs. shallow copying come up, and there's no magic solution
which always does what you want.  One thing i do know is that it's a hell of a
lot easier to automatically generate functions you want in Lisp than in C++.
From: Scott "TCB" Turner
Subject: Re: Problems Copying Structures
Date: 
Message-ID: <94565@aerospace.AERO.ORG>
Joe Keane writes:
>In article <·····@aerospace.AERO.ORG> ···@aerospace.aero.org (Scott "TCB"
>Turner) writes (about structure copying):
>>One of the better arguments for object-oriented programming.
>
>I don't see what object-oriented programming has to do with this.  The same
>problems with deep vs. shallow copying come up, and there's no magic solution
>which always does what you want.

Imagine trying to write a "copy" function in generic Lisp that will take
any type of object and provide an unlimited depth copy of that object.  
You do something along these lines:

	(defun copy (foo)
	   (cond ((type-1 foo)
			(apply #'create-new-type-1-w-elements
			       (mapc #'copy (destructure-type-1 foo))))
		 ((type-2 foo) ...)))

For each type that you know about, you destructure it, copy all the 
elements and then put it back together into a new gestalt.

Problem is, this requires that you know how to destructure and create
each possible type that will ever exist in your system.  Difficult.

In object-oriented programming, each type simply has an operation
"copy" that knows how to destructure and create that type and "voila!"
the problem is solved.

The same information and problems exist in either case.  OOP is not a
panacea, no matter what certain C++ cultists seem to think.  But OOP
does make this problem more tractable (and expandable) but organizing
the information wisely.

					-- Scott Turner