Subject: Re: Help on places and setf needed From: Erik Naggum <email@example.com> Date: Fri, 08 Mar 2002 05:43:53 GMT Newsgroups: comp.lang.lisp Message-ID: <firstname.lastname@example.org> * email@example.com (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.