3

I'm writing a sketch in Clojure/Quil in fun(ctional)-mode.

Sometimes, I want to be able to inspect what the current state holds.

However, when I try to call Quil's state from the REPL I get the following:

(q/state) ==>
NullPointerException   clojure.core/deref-future (core.clj:2208)

Not sure if this is relevant, but the same happens with drawing functions from the REPL:

(q/rect 0 0 10 10)

How can I get the current state to inspect it in the REPL?

cwj
  • 2,473
  • 5
  • 28
  • 38

2 Answers2

1

Not sure which function exactly you are talking about since you do not post code so this is a bit of a blind shot.

You could try to see the state-atom:

(require '[quil.core :as q])

;; both should do the same

@(q/state-atom)
(q/state) ;; is that what you were doing ?

The state function you seem to refer to optionally takes a parameter, for instance, and returns the state-atom when no parameter is passed:

(q/state :image)

In any case, it is generally a good idea to look at the tests of a Clojure library, and the code in this case seems very well documented.

nha
  • 17,623
  • 13
  • 87
  • 133
  • This question concerns the REPL mostly. Sorry I couldn't clarify this much sooner. I'll try the above though. – cwj Jul 12 '16 at 19:33
1

In order to call Clojure/Quil functions directly in the REPL, they need to be wrapped with the current sketch:

(quil.applet/with-applet hello-quil.core/hello-quil 
  (quil.core/random 10)) 

To access the state you can do this:

(require '[quil.core :as q])

(quil.applet/with-applet hello-quil.core/hello-quil 
  (q/state)) 

This is taken directly from the Quil wiki: Dynamic Workflow (for REPL)

DanEEStar
  • 6,140
  • 6
  • 37
  • 52