guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
334 stars 22 forks source link

setf-ing objects with let-match[1] #111

Closed digikar99 closed 4 years ago

digikar99 commented 4 years ago

Is this a bug or working-as-designed?

CL-USER> (defstruct foo slot-1)
FOO
CL-USER> (defparameter f (make-foo))
F
CL-USER> (trivia:let-match1 (foo slot-1) f (setf slot-1 2))
2
CL-USER> (foo-slot-1 f)
NIL
CL-USER> (with-slots (slot-1) f (setf slot-1 2))
2
CL-USER> (foo-slot-1 f)
2

If working-as-designed, are there issues making let-match1 behave compatibility with with-slots or any design decisions?

Thanks!

guicho271828 commented 4 years ago

You should use the place pattern

guicho271828 commented 4 years ago

(foo :slot-1 (place slot-1)) or (foo (slot-1 (place slot-1)))

digikar99 commented 4 years ago

Thanks! I have editted the entry on Special Patterns to include the mention of place pattern. (Found the wiki page mention from the cookbook.)