Lisp HUG Maillist Archive

Unable to render article 14489 because of ":DEFAULT stream decoding error on #<SB-SYS:FD-STREAM for \"socket 192.168.43.216:64116, peer: 116.202.254.214:119\" {100598ACA3}>: the octet sequence #(233 97 110) cannot be decoded." error

Re: #'(setf ...) in LW


On 27 Aug 2017, at 19:28, Yuri Davidovsky <yury.davidouski2@mail.dcu.ie> wrote:

Hi there,

came across it in LW 6.1.1 today, have a look at this example:

(defstruct test gan ga)

This will define a small struct, of course, with two slots. Let's create one and set one of the slots:

CL-USER> (setf a (make-test))
#S(TEST :GAN NIL :GA NIL)

CL-USER> (setf (test-gan a) 10)
10

CL-USER> a
#S(TEST :GAN 10 :GA NIL)



So far so good, now let us try to do it a bit differently:

CL-USER> (funcall #'(setf test-gan) 5 a)

which results in an error:

Error: Undefined function (SETF TEST-GAN) in form (FUNCTION (SETF TEST-GAN)).


Is this a behaviour expected from an implementation?

Yes. 

Implementation may implement the accessors to structures in other ways than a setf function.

If you want a setf function, use a CLOS class. (It will be a setf generic function of course).
cf. the Notes in clhs defstruct.

-- 
__Pascal J. Bourguignon__



Updated at: 2020-12-10 08:30 UTC