Code Monkey home page Code Monkey logo

Comments (9)

inconvergent avatar inconvergent commented on May 18, 2024

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.

inconvergent avatar inconvergent commented on May 18, 2024

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.

vydd avatar vydd commented on May 18, 2024

@inconvergent Weird. Thanks for reporting this. I'll try to find some time to look at it during the weekend.

from sketch.

inconvergent avatar inconvergent commented on May 18, 2024

@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.

Inc0n avatar Inc0n commented on May 18, 2024

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.

Inc0n avatar Inc0n commented on May 18, 2024

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.

death avatar death commented on May 18, 2024

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.

Inc0n avatar Inc0n commented on May 18, 2024

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.

inconvergent avatar inconvergent commented on May 18, 2024

the double evaluation seems to be fixed when using new defsketch macro

from sketch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.