Double evaluation in defsketch custom bindings
Gleefre opened this issue · 2 comments
Intro
Hi!
As mentioned before in this issue(#33), initforms of custom bindings in defsketch
macro are evaluated twice. (@inconvergent wrote that it seemed to be fixed. Unfortunately, I still observe this issue using both quicklisp version and this repo version.)
Examples
Here is my simple example:
(ql:quickload :sketch)
(use-package :sketch)
(defparameter *result* ())
(defsketch double-evaluation ((hi (push "world" *result*)))
(text (format nil "~a" *result*) 100 100))
(make-instance 'double-evaluation)
This will display a text (world world)
instead of just (world)
.
As a more complicated example - it seems that Qelt doesn't run properly with current version of sketch because of that.
Solution?
I think that I have found when this issue was introduced - 19fe205:
implementation of make-custom-slots-setf
function changed from
(defun make-custom-slots-setf (sketch bindings)
`(setf ,@(mapcan (lambda (binding)
`((,(binding-accessor sketch binding) instance) ,(car binding)))
bindings)))
to
(defun make-custom-slots-setf (sketch bindings)
`(setf ,@(mapcan (lambda (binding)
`((slot-value instance ',(car binding)) ,(cadr binding)))
bindings)))
Notice that second argument changed from (car binding)
, which refers to the binding name, to (cadr binding)
, which refers to the binding initform.
So, the patch proposed in this comment (#33 (comment)) should be the solution to this issue.
I must have made a mistake when I checked this the last time, sorry
Thanks! I merged the proposed change.