From ... Path: archiver1.sj.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!newsgate.cistron.nl!newsfeeds.belnet.be!news.belnet.be!npeer.kpnqwest.net!nreader2.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: [Q] Limitation of variables? References: <100520011607240096%sungwoo@cad.strath.ac.uk> <110520011712366532%sungwoo@cad.strath.ac.uk> Mail-Copies-To: never From: Erik Naggum Message-ID: <3198600534513378@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 51 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 11 May 2001 20:10:19 GMT X-Complaints-To: newsmaster@Norway.EU.net X-Trace: nreader2.kpnqwest.net 989611819 193.71.66.150 (Fri, 11 May 2001 22:10:19 MET DST) NNTP-Posting-Date: Fri, 11 May 2001 22:10:19 MET DST Xref: archiver1.sj.google.com comp.lang.lisp:9884 * Sungwoo Lim > Actual codes are as below. > > (defstruct stroke-info > (first-x 0.0 :type double-float) > (first-y 0.0 :type double-float) > ........ > (whatever 0 :type integer)) > > (setq a1 (make-stroke-info) > (defun put-stroke-info (a1 ... a93) > (setf (stroke-info-first-x a1) a2 > (stroke-info-first-y a1) a3 > ........ > (stroke-info-whatever a1) a93)) Does this imply that you reuse the instance assigned in a1? I think that is fairly bad style. What if somebody kept a pointer to that instance? What you do here requires an "ownership protocol" such that those who think they might want to retain a pointer to the object longer than the next instance, will have to make a copy. Violations of this protocol means that some user of the instance will find that the data changes. I suggest that you create a new instance every time you have a "stroke" and instead of this "put-stroke-info", use the boa constructor option to defstruct to make all of this (much, MUCH) more palatable. (defstruct (stroke-info (:constructor make-stroke-info (first-x first-y ... whatever))) (first-x 0.0 :type double-float) (first-y 0.0 :type double-float) ... (whatever 0 :type integer)) Please note that the list of arguments to make-stroke-info (constructor) may contain complex argument relationships and arbitrary computations. The boa constructor assigns values to slots By Order of Arguments, and you can use the value of previously specified arguments and even the presence of such arguments in the boa lambda list. Note also that the list of arguments to the simplest boa constructor may be computed from the defstruct body, which a little snippet of Emacs Lisp code can do for you if you do not want to write your own simple macro. Also note that you defstruct by default makes a copy-stroke-info function that copies every slot value from one instance to another such that the slots are eql after the copy. #:Erik -- Travel is a meat thing.