Is a setfable the same as a place in CLHS and a location in Norvig's PAIP?
I'm trying to figure out what exactly a place is in Common Lisp but to me the HyperSpec's explanation
place n. 1. a form which is suitable for use as a generalized reference. 2. the conceptual location referred to by such a place[1].
is only of limited help.
(I know it's not really the kind of question that suits SO but if someone knows a good article that explains setfable/place/location I'd appreciate a link/reference)
Originally mutable data structure has a getter AND a setter. Example for
car/rplacaandcdr/rplacd:In this example the getter are
carandcdrfor cons cells. The setters arerplaca(replace car) andrplacd(replace cdr).Every mutable data structure has that and usually there is no systematic way to guess the name of the setter from knowing the name of the getter.
Thus the idea was to have a registry of getter and setter. Register a setter for a getter and the user has only to know the getter. The
setfmacro (and others likeincf,decfand also user defined macros) then does a lookup of the setter for the used getter.The example above with the
setfmacro looks like this:As you see the use of
rplacaandrplacdhas been replaced by thesetfmacro.Thus a place is basically a registered form, for which there is a setter. defsetf and define-setf-expander are used for that.
define-modify-macro is used to define a macro, which can modify a place.
For example we can define a way to multiply the value of a place, similar to
incf(increment a place) anddecf(decrement a place).This feature is old and originally the word field was used instead of place. Thus the macros able to use a place end with f (field).