In Practical Common Lisp chapter 17. Object Reorientation: Classes section Accessor Functions, I was finding it difficult understanding the way SETF
is being extended.
The functions:
(defun (setf customer-name) (name account)
(setf (slot-value account 'customer-name) name))
bank-account
class definition:
(defclass bank-account ()
((customer-name
:initarg :customer-name
:initform (error "Must supply a customer name."))
(balance
:initarg :balance
:initform 0)
(account-number
:initform (incf *account-numbers*))
account-type))
What I don't understand:
in the expression
(setf (customer-name my-account) "Sally Sue")
does(customer-name my-account)
return a SETFable slot-valuecustomer-name
of the the classbank-account
which thenSETF
uses to set the value to "Sally Sue"?is
(setf (customer-name my-account) "Sally Sue")
actually calling the function above?as defined above is
setf customer-name
a function?in the function above is
customer-name
in(setf customer-name)
and'customer-name
in the body referring to the same thing?the section states
second element is a symbol, typically the name of a function used to access the place the SETF function will set
if that's the case then why use the
slot-value
function inside the function's definition when the function can be used to access the place?
(setf (customer-name my-account) "Sally Sue")
calls(setf-customer-name)
? But that function expects two arguments and only one,"Sally Sue"
, is passed. – Forefather