The less-familiar parts of Lisp for beginners — with-accessors

The with-accessors macro is a syntactic shortcut that simplifies forms that manipulate the slots of an instance.  It creates a shorthand expression in a new lexical environment that replaces an accessor form acting on an instance with a simple symbol.  This symbol is setf-able, it is not a local variable that is filled in with the value of the slot.  In C++ parlance, this macro creates references to members within an object.

There is a bit of a tradeoff between convenience and clarity here.  While the macro allows the programmer to avoid typing a lot of accessor forms, the symbols created are not, at a glance, obviously manipulating an instance, which can lead to a bit of confusion when reading the code.  Of course, it comes down to a personal preference, there’s nothing you can do with with-accessors that you cannot easily achieve with more familiar operations.

Leave a Reply

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

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