Comments (9)
I've noticed that if i print the assignment of b
inside the macro
(b (print (change-state a)))
this will happen twice. Which i assume is the explanation for this behaviour i'm seeing.
from sketch.
For anyone else who ends up here. Perhaps this is an example of the way setup should be used: https://github.com/vydd/qelt/blob/master/qelt.lisp#L275 (I will try this, and report back)
from sketch.
@inconvergent Weird. Thanks for reporting this. I'll try to find some time to look at it during the weekend.
from sketch.
@vydd no problem. I had a look at the expanded code from the macro. I'm not too sure about how classes/methods work, but i noticed that i could make the following change to get the behaviour i need (expanded with pg's mac-macro):
(PROGN
(DEFCLASS NIER (SKETCH)
((A :INITARG :A :ACCESSOR NIER-A) (B :INITARG :B :ACCESSOR NIER-B)))
(DEFMETHOD PREPARE PROGN
((INSTANCE NIER) &REST INITARGS &KEY &ALLOW-OTHER-KEYS)
(DECLARE (IGNORABLE INITARGS))
(LET* ((FULLSCREEN (SLOT-VALUE INSTANCE 'FULLSCREEN))
(COPY-PIXELS (SLOT-VALUE INSTANCE 'COPY-PIXELS))
(Y-AXIS (SLOT-VALUE INSTANCE 'Y-AXIS))
(TITLE
(IF (GETF INITARGS :TITLE)
(SLOT-VALUE INSTANCE 'TITLE)
"weir"))
(WIDTH
(IF (GETF INITARGS :WIDTH)
(SLOT-VALUE INSTANCE 'WIDTH)
1000))
(A (OR (GETF INITARGS :A) (MAKE-HASH-TABLE :TEST #'EQUAL)))
(B (OR (GETF INITARGS :B) (CHANGE-STATE A)))
(HEIGHT
(IF (GETF INITARGS :HEIGHT)
(SLOT-VALUE INSTANCE 'HEIGHT)
1000)))
(DECLARE
(IGNORABLE TITLE WIDTH HEIGHT FULLSCREEN COPY-PIXELS Y-AXIS TITLE WIDTH A
B HEIGHT))
(SETF (SKETCH-TITLE INSTANCE) TITLE
(SKETCH-WIDTH INSTANCE) WIDTH
(SKETCH-HEIGHT INSTANCE) HEIGHT
(SKETCH-FULLSCREEN INSTANCE) FULLSCREEN
(SKETCH-COPY-PIXELS INSTANCE) COPY-PIXELS
(SKETCH-Y-AXIS INSTANCE) Y-AXIS)
; replace this ------------------------------------
;(SETF (SLOT-VALUE INSTANCE 'A) (MAKE-HASH-TABLE :TEST #'EQUAL)
; (SLOT-VALUE INSTANCE 'B) (CHANGE-STATE A))
; with this? ----------------------------------------
(SETF (SLOT-VALUE INSTANCE 'A) A
(SLOT-VALUE INSTANCE 'B) B))
(SETF (ENV-Y-AXIS-SGN (SLOT-VALUE INSTANCE '%ENV))
(IF (EQ (SLOT-VALUE INSTANCE 'Y-AXIS) :DOWN)
1
-1)))
(DEFMETHOD DRAW ((INSTANCE NIER) &KEY &ALLOW-OTHER-KEYS)
(WITH-ACCESSORS ((TITLE SKETCH-TITLE) (WIDTH SKETCH-WIDTH)
(HEIGHT SKETCH-HEIGHT) (FULLSCREEN SKETCH-FULLSCREEN)
(COPY-PIXELS SKETCH-COPY-PIXELS) (Y-AXIS SKETCH-Y-AXIS))
INSTANCE
(WITH-SLOTS (TITLE WIDTH A B HEIGHT)
INSTANCE
(PRINT (LIST :A (GETHASH 'V A) :B (GETHASH 'V B)))
(BACKGROUND (GRAY 0.1)))))
(MAKE-INSTANCES-OBSOLETE 'NIER)
(FIND-CLASS 'NIER))
A naive fix that addresses this could look something like this: inconvergent@8ceda09
But again, I'm unsure of what else i might be breaking here.
Best, A
from sketch.
Yes this is still the problem til this day, I think the mentioned commit would resolve the problem, if not at least it's at the right direction.
from sketch.
Also, may i suggest a much more elegant fix, in defclass
, we could use initform
for each of the slots. instead of manually determine to initialise the slots with set default value or the pass in args in make-instances
from sketch.
Interestingly, I had a patch that's similar to inconvergent's but using the car of binding. See https://gist.github.com/death/73f001b54d23c7ba83f03c9ade7159ae
from sketch.
No yh it seems with cdr
it produces
(SETF (SLOT-VALUE SKETCH::INSTANCE 'CELL-SIZE) (10)
(SLOT-VALUE SKETCH::INSTANCE 'POS-VEC)
((MAKE-VEC2 :X (/ WIDTH 2) :Y (/ HEIGHT 2)))
(SLOT-VALUE SKETCH::INSTANCE 'RUNNING) (T))
when we defsketch with (cell-size pos-vec running) these slots, and car
actually uses the let binding variables and avoids re-evaluation.
But still, I think using initform
removes much of these unneeded code.
from sketch.
the double evaluation seems to be fixed when using new defsketch
macro
from sketch.
Related Issues (20)
- MAKE-LINE behaving oddly with small values of stroke weight HOT 2
- Improve speed of canvas painting HOT 3
- Add control flow functions from p5js HOT 2
- Make errors more recoverable HOT 6
- Correlated randomness HOT 3
- Support for saving animations HOT 2
- Add missing event-handling functions HOT 3
- Enable drawing in event-handling functions
- Greater control of execution loop HOT 1
- More flexible sketch class generation HOT 2
- Issue with FREE-RESOURCE
- Improved interactive development
- Drawing huge polygons HOT 2
- Video support? HOT 4
- No input on OS X HOT 2
- Can't quickload sketch HOT 1
- Input methods do not seem to work HOT 3
- incf in a let form HOT 2
- Further improvements / maintenance HOT 7
- defsketch bugs/surprises HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sketch.