Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!nntp.crl.com!pacbell.com!gw2.att.com!nntpa!ssbunews!iexist!not-for-mail
From: clarisse@iexist.flw.att.com
Subject: Re: Lisp Question
Message-ID: <DAAJ4A.Bnp@ssbunews.ih.att.com>
Originator: clarisse@tenet
Sender: clarisse@iexist (55437-olivier clarisse(haim)463)
Nntp-Posting-Host: tenet.flw.att.com
Organization: AT&T
References: <3ri5nq$fgc$1@mhafc.production.compuserve.com> <3rqenu$gda@tools.near.net> <DAAIq0.BJ2@ssbunews.ih.att.com>
Date: Sat, 17 Jun 1995 00:09:45 GMT
Lines: 43


|> >First, is there a way to do copy-by-value in LISP?  Specifically, 
|> >I don't want the new object to share anything with the old 
|> >object.
|> 
|> Not even interned symbols?  Someone suggested a solution using
|> WRITE-TO-STRING and READ-FROM-STRING, but that will still share symbols.

That's right and if you don't want to share symbols at all
you can use strings (if you did not want Lisp to be a symbolic
language) or use MAKE-SYMBOL.

Now should symbols created by MAKE-SYMBOL (e.g. GENSYM) be shared
by the copy of not? If they are not and one of the objects copied
contains an expanded interpreted lambda, the lambda from the copy
will probably not work [e.g. a compiler will complain that variable
#:G1234 is declared and not used and that several other variables
#:G1234, #:G1234 and #:G1234 are now assumed special...
	- It's amazing how good Lisp compilers can be.]

This points right back to the READ-FROM-STRING of WRITE-TO-STRING
solution posted earlier to make copies of objects that contain
any form of circulary (a symbol is an object so an interpreted
lambda with GENSYMs is an object with circularities too).
It is then safer to insure the COPY-ALL solution always has :CIRCLE T.

(defmethod copy-all (object)
  (with-standard-io-syntax	;Safer version
    (read-from-string (write-to-string object :circle t))))

And how about numbers? Should they be the same (EQ) or copied
(EQL or only EQUAL)? COPY-ALL does it right, just as the reader.

|> -- 
|> Barry Margolin
|> BBN Planet Corporation, Cambridge, MA
|> barmar@{bbnplanet.com,near.net,nic.near.net}
|> Phone (617) 873-3126 - Fax (617) 873-5124
-- 
----------------
Olivier Clarisse	     "Languages are not unlike living organisms
Member of Technical Staff     can they adapt and improve to survive?"
AT&T Bell Laboratories
