In many cases, accessing and configuring data requires two things:
- way to get something from a data structure
- way to set something in the data structure
Thus, one could define the setter function and the getter function. For simple cases, they can also look simple. But for complex cases, they cannot. Now, if you know the name of the recipient, what is the name of the setter? Or: if you know the name of the setter, then what is the name of the recipient?
In general, Lisp has the idea that you only need to know the name of the recipient.
getter called let's say GET-FOO
then the setter function is called (SETF GET-FOO) . Always.
The setter function can be called as follows: (setf (get-foo some-bar) new-foo) . Always.
So you are writing a GET-FOO function. You also write a function (SETF GET-FOO) , and Common Lisp registers it as a setter function.
(SETF GET-FOO) is a list. This is also the name of the function. Here we have an exception: Common Lisp sometimes allows a list as a function name. Thus, not all function names are characters, some are actually lists.
(setf (customer-name my-account) "Sally Sue") actually a call to the given setter. my-account is a variable whose value will be bound to the account variable of the installer. "Sally Sue" is a string and it will be bound to the installer name variable.
As a developer, you only need to know the recipient:
(defun (setf customer-name) (name account) (setf (slot-value account 'customer-name) name))
The above defines a setter function called (setf customer-name) .
CL-USER 80 > (function (setf customer-name)) #<interpreted function (SETF CUSTOMER-NAME) 40A00213FC>
When a function is called with the SETF macro, it calls another setter - this time using access to the slot value through the slot name.