Path: utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!rutgers!mcnc!gatech!udel!wuarchive!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!aero!srt From: srt@aerospace.aero.org (Scott "TCB" Turner) Newsgroups: comp.lang.lisp Subject: Re: Problems Copying Structures Keywords: defstruct structures copying Message-ID: <94565@aerospace.AERO.ORG> Date: 14 Dec 90 22:25:29 GMT References: <1990Dec8.180825.21702@Think.COM> <93985@aerospace.AERO.ORG> <4083@osc.COM> Organization: The Aerospace Corporation, El Segundo, CA Lines: 35 Joe Keane writes: >In article <93985@aerospace.AERO.ORG> srt@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