The less-familiar parts of Lisp for beginners — remprop

Now, we’ll discuss remprop a bit.  You may recall an earlier article where I discussed the concept of Lisp symbols.  There, I talked about symbols having five fields, such as the function field or the value field.  I mentioned the “property list” field, but didn’t say anything more about it.  Now, the time has come to examine that.

Now, while a symbol can have an associated value field, it can also have an associated property list that allows it to hold a set of key/value pairs.  A property list is a list with an even number of entries, in which each successive pair of entries represents a key and associated value.  Conceptually, but not structurally, it resembles an association list.  The remprop function allows the user to remove the first pair whose key is eq to the value passed in the function’s second argument.  Note that there is no way to modify the test function, and the use of eq rather than equal means that the programmer should avoid assigning to the property list with keys that are numbers or characters.

Now, I haven’t found reasons to use property lists so far.  In other projects, they have been used to attach meaningful data to functions.  For instance, one might attach a callback function to a symbol associated with a particular function, rather than building a struct that contains the function and its associated callback.

One warning: do not think of property lists as another way to build slots in a structure, the property lists are bound to a symbol, not to an instance, and copying the value of a symbol does not copy its property list.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.