Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging functions for debugging #315

Closed
nbeloglazov opened this issue Jul 22, 2019 · 5 comments
Closed

Add logging functions for debugging #315

nbeloglazov opened this issue Jul 22, 2019 · 5 comments

Comments

@nbeloglazov
Copy link
Member

Debugging Quil sketches is quite hard. Often you need to see state of the sketch but adding println to sketch causes never ending stream of text in console. Quil should provide some functionally to aid debugging. For example we could add print-first-n function that when called prints provided arg only the first n iterations. Similarly we could add print-every-n-sec to see samples during sketch run.

@anthonygalea
Copy link
Member

Is this what you have in mind?

(def p (volatile! nil))

(defn print-first-n
  [n & more]
  (locking p
    (when (nil? @p)
      (vreset! p n))
    (when (pos? @p)
      (vswap! p dec)
      (apply print more))))

You can see it in use in this sketch: http://quil.info/sketches/show/7f7cc14db3a5ba44cb528cb7f3fd69763cabf8e53183f13bb8ba9e5a8ac35469

@nbeloglazov
Copy link
Member Author

Yes, something like that. Though we can use frame-count instead of mutable object to keep things simpler. Otherwise you'd need to store the p on sketch itself as it can't be global?

@anthonygalea
Copy link
Member

Ah yes, using frame-count is a lot better:

(defn print-first-n
  [n & more]
  (when (<= (q/frame-count) n)
    (apply print more)))

Regarding printing every n seconds, do you see an alternative to the following approach which requires storing the last-time?

(def last-time (atom 0))

(defn print-every-n-millisec
  [n & more]
  (let [elapsed (q/millis)]
    (when (< n (- elapsed last-time))
      (reset! last-time elapsed)
      (apply print more))))

@nbeloglazov
Copy link
Member Author

Trying to think if we can avoid atom, but can't think of any approach. So probably yeah - that would be the way to do it. The only thing I mentioned before, it would be good if last-time is tied to sketch instead of being global variable shared between all sketches.

@nbeloglazov
Copy link
Member Author

We have internal-state function for similar purposes (though doc string lies, this state should not be visible to users).

anthonygalea added a commit to anthonygalea/quil that referenced this issue Jul 30, 2019
anthonygalea added a commit to anthonygalea/quil that referenced this issue Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants