From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news.brutele.be!nmaster.kpnqwest.net!nreader1.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Help on places and setf needed References: <8bb226c3.0203070805.317b2385@posting.google.com> Mail-Copies-To: never From: Erik Naggum Message-ID: <3224555042407102@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 30 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 08 Mar 2002 05:43:53 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader1.kpnqwest.net 1015566233 193.71.199.50 (Fri, 08 Mar 2002 06:43:53 MET) NNTP-Posting-Date: Fri, 08 Mar 2002 06:43:53 MET Xref: archiver1.google.com comp.lang.lisp:28101 * mrstatex@yahoo.de (Martin) | How do I store a reference to the element, so that "nth" is computed | only once? That is not how we do things in Common Lisp. In C-like languages, you can compute a "reference" to the location of an object, i.e., some sort of indirect object that does not refer to an object, but to another pseudo-object that refers to this other object, and you can write into pseud-objects from these indirect objects. Useful pseud-objects are generally subobjects of various containers or aggregate object types, such as array, structure, or class slots. Common Lisp does not offer you any way to refer, directly or indirectly, to sub-objects, only to whole objects. The cons cell that Barry Margolin suggested is basically the smaalest container we have and nthcdr is the preferred way to access it. Similarly simple accessors do not generally exist elsewhere. However, this obsession with efficiency at this level is common to those who have seen too much exposure to really bad languages, such as those in the C family. There is nothing with the kind of pointers that C has, as long as the programmer has no access to them. That is, if the compiler can figure out that you will repeatedly refer to the same location, it should be free to keep a pointer around rather than repeatedly re-compute the same location, indeed, you should _expect_ this to be the case, but there are limits to how far common subexpression elimination can get you, so there is good reason to try to make the job easier for the compiler. /// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.