quil

leifericf 2022-01-03T09:22:18.016900Z

I’m following https://github.com/quil/quil/wiki/Dynamic-Workflow-(for-REPL), and it is working. However, it’s not a particularly smooth experience, since it relies on running commands “manually” directly in the REPL. I’m currently trying to create a smooth workflow from within https://code.visualstudio.com and https://calva.io, with my editor “jacked in” to the REPL via Leiningen. My goal is to work in the editor, without needing to issue commands directly in the REPL. But executing expressions like (use :reload 'quil-workflow.dynamic) and (defonce sketch (create-sketch)) from the editor results in error messages. Has anyone succeeded in creating a smoother interactive workflow with VS Code and Calva? In a perfect world, the rendered image would also show up directly within a new tab in VS Code, so that everything is right there. I’m not sure whether it’s possible to “embed” OpenGL into VS Code like that, though.

leifericf 2022-01-04T12:11:54.047600Z

@pez: FYI, I have created an issue for the jEnv need, as we discussed above: https://github.com/BetterThanTomorrow/calva/issues/1452

Tero Matinlassi 2022-01-04T12:27:27.048Z

@leif.eric.fredheim Do you have eval "$(jenv init -)" in your shell’s rc file (e.g. .zshrc)?

Tero Matinlassi 2022-01-04T12:31:23.048200Z

I’m asking because I have that and it seems to me that if I open a new project (with Calva), I get Java 17 environment, but if I open an existing project that has .java-version file, it will use it.

1
😮 1
leifericf 2022-01-04T12:32:12.048400Z

@tero.matinlassi: Yeah, it’s in there 🙂

Tero Matinlassi 2022-01-04T12:32:58.048900Z

Interesting… then I’m not sure why it works for me 🙂

leifericf 2022-01-04T12:33:40.049100Z

That’s fascinating! Maybe I’ve messed up something else in my environment 🤔

pez 2022-01-04T12:36:27.049400Z

I was about to ask on the issue. Have you restarted VS Code since you updated your .zshrc?

🤔 1
pez 2022-01-04T12:37:22.049600Z

You might even have to start VS Code from the terminal to have it inherit the change, until you have restarted the machine.

leifericf 2022-01-04T14:36:12.050700Z

Oh! I was not aware of that. I'll try to reboot my machine, then try again to see if it works!

pez 2022-01-04T15:28:37.050900Z

This is quite dynamic, wouldn’t you say? 😃

💯 3
😯 2
leifericf 2022-01-04T15:47:10.051700Z

Wow! That’s fantastic, @pez! Exactly what I was trying to achieve! Bravo! 👏 By the way, I think you guys were into something regarding jEnv and Calva. Upon rebooting my Mac and starting VS Code, I noticed this error (see screenshot). Which led me to https://code.visualstudio.com/docs/supporting/faq#_resolving-shell-environment-fails with more info: > “[…] when launched via a UI gesture, VS Code will start a small process to run (or “resolve”) the shell environment defined in your `.bashrc` or `.zshrc` files. If, after 10 seconds, the shell environment has still not been resolved or resolving failed for any other reason, VS Code will abort the “resolve” process […] So it looks like my .zshrc is messed up or something… looking into that now

pez 2022-01-04T15:48:51.052400Z

I have had that situation… How long does it take for you to get a prompt when opening a new terminal?

👍 1
leifericf 2022-01-04T16:20:29.052700Z

I found the culprit by enabling start-up profiling in https://iterm2.com, i.e., starting zsh with some additional options, like so: /bin/zsh -i -x. Turns out some of the https://ohmyz.sh plug-ins were causing a long start-up time. Interestingly, the start-up time was no more than 1-2 seconds with iTerm2, but it was slower from VS Code. Seems to be fixed now that I removed a bunch of plug-ins that I wasn’t using anyways (I had just forgotten about enabling them some years ago).

1
leifericf 2022-01-04T17:19:50.053200Z

It works like a dream now! (The GIF is a bit laggy, but the experience in CS Code is not.)

pez 2022-01-04T21:42:00.053800Z

Awesome.

Tero Matinlassi 2022-01-03T10:59:49.018Z

I did try to use Quil in VS Code/Calva, but I think I couldn’t get “dynamic workflow” working at all (it’s been a while, so I don’t remember the details). The closest I could get to working was the “alternative” workflow described later in the same page. It wasn’t perfect, for example every time I got an exception in the code, I had to restart the application to resume development. So, not quite smooth…

Tero Matinlassi 2022-01-03T11:04:16.018200Z

Would definitely love to see a smooth workflow with Calva, if that’s possible. And of course, working with Processing 4 would be nice (working with old JDK’s is painful..)

leifericf 2022-01-03T11:04:28.018400Z

@tero.matinlassi: Yes, I had the same experience. I have thus far not been able to get the “alternative REPL workflow” working with VS Code and Calva; only the first approach (but I had to make some code changes to get it working).

leifericf 2022-01-03T11:06:02.018600Z

I don’t have enough experience with Clojure or TypeScript (used to develop VS Code plug-ins and extend Calva) to get it working. But I will let you know if I manage to figure it out.

leifericf 2022-01-03T11:09:57.019Z

What I dont understand is that, when “jacked in” via Leiningen, evaluating an expression in the editor is supposed to be effectively the same as typing the expression directly into the REPL. So I thought it would work to evaluate (use :reload 'quil-workflow.dynamic) in the editor, but it does not for some reason. I suppose one would have to create some kind of wrapper or VS Code plug-in (or extend Calva) to get it working well.

pez 2022-01-03T11:33:46.019200Z

I haven’t read the guide yet, but generally, if the workflow relies on the REPL, then it should be possible to use Calva with it. So your expectations there are correct, I’d say, @leif.eric.fredheim. I expect this to be less about Calva and more about setting up the code structure to support the workflow. Calva does not do much in the way of magic, it just an interface to the REPL, really. It was a long time ago I played anything with quil, I will read the guide and see if I can get a nice workflow going.

👍 1
leifericf 2022-01-03T11:45:03.024600Z

Thanks, @pez! I appreciate you taking the time to comment and check it out. I also suspect the issue is code organization, some limitation of Quil’s architecture (unlikely), or perhaps some more fundamental limitation of Processing and OpenGL (Quil’s dependencies).

pez 2022-01-03T11:52:13.024800Z

I have read the guide now, we should at least be able to get those things working. I’ll fiddle around a bit and see what I can cook up. On Wednesday I have a full day for Calva things so will try to make a video with my findings. Similar to this one: https://www.youtube.com/watch?v=fJpDztSR53E&t=1s

❤️ 1
leifericf 2022-01-03T12:04:04.025500Z

You’re awesome, @pez! No rush, and thanks again for Calva and your community efforts. I have enjoyed several of your YouTube videos already 🙂 When I get up to speed with Clojure, VS Code and Calva, I will be sure to contribute whenever possible.

❤️ 1
leifericf 2022-01-03T12:28:04.025900Z

@pez: One small gotcha from the Quil guide: I had to change one dependency from [org.clojure/clojure "1.6.0"] to [org.clojure/clojure "1.8.0"] in project.clj for the first example to work, because I was getting an error that CIDER requires a newer version of Clojure. And I have to start the REPL manually in the terminal, then evaluate (use :reload 'quil-workflow.dynamic) directly in the REPL. Then it works. But the same thing does not work when using Calva’s “jack in” and evaluating the same expression via the VS Code editor.

pez 2022-01-03T12:37:42.026800Z

Thanks.

pez 2022-01-03T12:37:55.027Z

Very strange with the different results.

leifericf 2022-01-03T12:54:17.029300Z

Indeed, that’s what I’m thinking, too. But I’m quite new to all of this, so there is a decent chance that I’m just doing something incorrectly as well. That is always my first assumption 😅

pez 2022-01-03T12:58:16.029900Z

I have many hours of training in this game, let’s hope I can leverage it. 😃

1
pez 2022-01-03T14:35:49.030200Z

I don’t get any errors evaluating the use form here

(comment
  (use :reload 'quil-workflow.sketch)
  )
(Where sketch is what I named my dynamic namespace.)

😮 1
pez 2022-01-03T14:37:11.030400Z

I’m using quil 0.4.4-SNAPSHOT. though, so that might be what is different. Or that I use Java 13 and not 8, as you do.

👍 1
pez 2022-01-03T14:37:33.030600Z

(I’m also using deps.edn, just because, haha.)

pez 2022-01-03T14:56:34.031300Z

Generally it seems better to try free ourselves out of Java 1.8 jail and unless necessary drop Leiningen for deps.edn/tools-build.

👍 1
pez 2022-01-03T15:04:33.031500Z

That said. I now tried with Java 1.8 and quil 3.1.10 and get no errors either.

😲 1
leifericf 2022-01-03T15:14:07.031900Z

@pez: Thanks for checking/confirming! Then most likely I’m being a dunce, or something is wrong with my system. I’m going to try some more to figure out what I’m doing wrong. And I also need to learn how to use deps.edn/tools-build.

pez 2022-01-03T15:15:13.032100Z

I’ll try to describe what I am doing in a short blog post and probably a video as well, and maybe we can find where things go wrong for you.

pez 2022-01-03T15:16:58.032400Z

There is not much need for the dynamic workflow or anything, afaict. It’s enough to re-evaluate a function using alt+ enter to update the quil as it is running.

😮 1
leifericf 2022-01-03T15:19:03.032700Z

Which function are you evaluating to update the drawing?

pez 2022-01-03T15:23:31.032900Z

I’m using these from the leiningen quil template:

(defn setup []
  ; Set frame rate to 30 frames per second.
  (q/frame-rate 30)
  ; Set color mode to HSB (HSV) instead of default RGB.
  (q/color-mode :hsb)
  ; setup function returns initial state. It contains
  ; circle color and position.
  {:color 0
   :angle 0})

(defn update-state [state]
  ; Update sketch state by changing circle color and position.
  {:color (mod (+ (:color state) 0.7) 255)
   :angle (+ (:angle state) 0.1)})

(defn draw-state [state]
  ; Clear the sketch by filling it with light-grey color.
  (q/background 240)
  ; Set circle color.
  (q/fill (:color state) 255 255)
  ; Calculate x and y coordinates of the circle.
  (let [angle (:angle state)
        x (* 150 (q/cos angle))
        y (* 150 (q/sin angle))]
    ; Move origin point to the center of the sketch.
    (q/with-translation [(/ (q/width) 2)
                         (/ (q/height) 2)]
      ; Draw the circle.
      (q/ellipse x y 100 100))))
It renders a circle spinning around, changing color. If I change the + to a - for :angle in update-state and then evaluate the function, the circle changes spin direction.

👍 1
pez 2022-01-03T15:24:36.033100Z

Same with anything in draw-state.

leifericf 2022-01-03T15:26:51.033300Z

Ah, I see. I did get that working, but I couldn’t figure out how to update the rendered image without closing and reopening the OpenGL window, and that’s why I started looking at the “dynamic” guide instead. I will go back to that basic example, using the Quil Leiningen template, to see if I can get that working “dynamically” instead.

pez 2022-01-03T15:30:18.033700Z

Which rendered image?

leifericf 2022-01-03T15:33:34.033900Z

The spinning circles ☺️

leifericf 2022-01-03T15:36:45.034100Z

I do get the fresh project running with Java 8, but not with newer versions of Java. Shown here using terminal only, to eliminate other potential sources of error. Using Quil v3.1.0 in this case. Now moving to VS Code to try there…

pez 2022-01-03T15:52:35.034500Z

To @tero.matinlassi’s observation about recovering from errors, that too is simply a matter of reevaluating the functions when they are fixed, when I try it. But I’m not using the alternative workflow, of course, so the matter is probably about figuring out why simply re-evaluating the functions doesn’t work for everyone.

👍 1
leifericf 2022-01-03T15:56:08.034700Z

In VS Code, when I open core.clj (using the same project as shown in the previous screenshot), I get an error when I try to evaluate this expression on line 36. When I check my Java version in a VS Code terminal, it shows that I’m using Java 8 (which was error-free outside of VS Code). Perhaps VS Code and/or the REPL doesn’t “see” the Java 8 version set through jEnv? And the terminal is “tricking” me. Hmmm.

Tero Matinlassi 2022-01-03T15:59:57.035300Z

Now that I re-read some of the documentation, it actually states on the page about alternative workflow that (emphasis mine): > Note this isn’t perfect, for example, changes to setup or if an exception causes m/pause-on-error to trigger, will often require re-creating the window [..] I guess what I would want is that if I fix the error situation, it would continue without the need to re-evaluate sketch function (only needing to evaluate the part that caused the error), but I guess it’s just a limitation of the alternative workflow.

👍 1
leifericf 2022-01-03T16:02:32.035500Z

@tero.matinlassi: Yeah, I noticed that part as well for the “alternative workflow.” Now I’m back to trying the basic setup, using the vanilla Leiningen Quil template. It looks like @pez has gotten that to work in a “dynamic” way, by re-evaluating the functions in the template.

pez 2022-01-03T16:03:56.035800Z

To my experience jack-in will use the same java as used by a newly opened terminal pane.

leifericf 2022-01-03T16:05:10.036Z

Is there a built-in function of Clojure or the REPL that can be used to see which Java version has actually been loaded? 🤔 searching in docs

pez 2022-01-03T16:05:16.036200Z

That error does look like the error I got when using 3.1.0 and a >1.8 java…

👍 1
pez 2022-01-03T16:05:42.036500Z

(System/getProperty "java.version") should do it.

💯 1
🔥 1
pez 2022-01-03T16:06:09.036800Z

^edited 😃

leifericf 2022-01-03T16:06:41.037Z

Yes, it’s the same error I see when using 3.1.0 and > Java 1.8 in the terminal as well (shown in my first terminal screenshot above), so I suspect my “jack in REPL” is not using the Java specified by the .java-version file (created by jEnv).

pez 2022-01-03T16:08:24.037300Z

Could be. A way to get around it is to run the Copy Jack-in command line (or whatever the command is named). and paste that in the terminal and then connect, instead of using jack-in.

pez 2022-01-03T16:08:53.037500Z

(Or sdk-man 😃 )

pez 2022-01-03T16:09:29.037700Z

Or start VS Code from a terminal, using the code command.

pez 2022-01-03T16:10:27.037900Z

Or, if, jEnv can read from an environment variable use the jackInEnv setting.

leifericf 2022-01-03T16:10:47.038100Z

Aha! That seems to be the problem! The terminal in VS Code tells me I’m running Java 8, but the “jack in”/REPL actually loaded Java 15 somehow.

Tero Matinlassi 2022-01-03T16:11:28.038500Z

I think I also had some trouble with VS Code and multiple Java versions, but unfortunately I don’t remember how I did get around that… I think VS Code’s Java extension has some way to define the JDK in use but it might not be applied to anything else than (Java) code handled by that extension which was making things more complicated. Probably starting VS Code from terminal was the solution…

pez 2022-01-03T16:14:48.038700Z

Starting the VS Code from a terminal has the drawback that all jack-in sessions will use that Java version. At least for me, who juggles a lot of projects in parallel, that doesn’t work. sdk-man let’s me redefine default system java version at will. So when I have some project that needs some special java version I just use sdk-man.

pez 2022-01-03T16:17:25.039Z

I don’t understand why jack-in doesn’t get a java version from that .java-versionfile when using jEnv. But then again, TIL that there is a jEnv. 😃

leifericf 2022-01-03T16:23:57.039500Z

Great success! I got it working by using the Calva command “Copy Jack-in Command to Clipboard,” pasting/executing it in the terminal within VS Code, then using the Calva command “Start or Connect to a Clojure REPL” within my project. Man, Calva is amazing! Thanks, @pez! Next I will try to figure out how to get jEnv to play nicely with VS Code and Calva, but this is a great workaround.

🙏 1
🎉 1
pez 2022-01-03T16:28:08.039900Z

Do you have the :p3d renderer working?

leifericf 2022-01-03T16:30:35.040300Z

Haha! Every time I evaluate (use 'my-art.core :reload-all) (or with :reload) it creates a new window. But it’s super fast! I’ll try see if I can get :p3d to work as well (haven’t tried that at all yet, actually—not even directly in Processing).

pez 2022-01-03T16:34:27.040700Z

Are you doing defsketch in my-art.core?

pez 2022-01-03T16:35:33.040900Z

I get SIGKILL when trying :p3d so I have so far no reason to use Java 1,8. 😃

leifericf 2022-01-03T16:42:10.041100Z

Same. I just tried :p3d with Java 8, and it crashes the JVM. Tries and fails to dumps core 😅

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGILL (0x4) at pc=0x00007ff815ec07a3, pid=37157, tid=0x0000000000012a03
#
# JRE version: OpenJDK Runtime Environment (8.0_312) (build 1.8.0_312-bre_2022_01_01_23_04-b00)
# Java VM: OpenJDK 64-Bit Server VM (25.312-b00 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libdispatch.dylib+0x47a3]  _dispatch_assert_queue_fail+0x63
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/leif/art/my-art/hs_err_pid37157.log
#
# If you would like to submit a bug report, please visit:
#   
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Subprocess failed (exit code: 134)

leifericf 2022-01-03T16:51:12.041400Z

As far as I know, only the p2d and p3d Processing renderers are using OpenGL, and the default renderer when neither of those are specified (forgot what it’s called) does not. I seem to recall seeing something about that in one of the book I’m reading… searching in book Indeed! Found it. The default renderer uses Java 2D instead of OpenGL. This might explain why the OpenGL renderers dump core, even when the default renderer is working fine.

pez 2022-01-03T16:57:04.041900Z

Yeah, so until that’s sorted, seems like Quil 4.0.0-SNAPSHOT is best to use, right? 😃

leifericf 2022-01-03T16:57:56.042100Z

@pez: Yes, when I use defsketch in my-art.core, it opens a new sketch instead of updated the existing one. The same happens when I use (use 'my-art.core :reload), (use 'my-art.core :reload-all) and also (use 'my-art.core :update).

leifericf 2022-01-03T16:59:54.042300Z

My understanding from reading the GitHub issues (comments from the creator of Quil) is that Quil 4.0.0-SNAPSHOT does not work with p2d and p3d yet, but the older version with Java 8 is supposed to work. I think that’s the current “blocker” in the “Processing4" branch of Quil, of I’m not mistaken. I will go back to GitHub to check if I have understood that correctly.

leifericf 2022-01-03T17:16:17.042500Z

Yeah, https://github.com/quil/quil/issues/228#issuecomment-882219561 is the comment I was thinking of: > “You can try using quil 4.0.0-SNAPSHOT but p2d and p3d will likely not work.”

leifericf 2022-01-03T17:22:38.045200Z

By the way, would it be worth reporting a bug in some GitHub repo about “jack in”/REPL not picking up on the Java version defined by jEnv via .java-version? If that is indeed a valid bug, and not just a fluke on my system. I wouldn't know if that's a bug in VS Code, CIDER, or Calva… or somewhere deeper in Clojure.

pez 2022-01-03T17:29:30.046Z

It’s a valid feature request at least. Not sure we can fix it, but to have an issue to track the need would be great.

👍 1
pez 2022-01-03T17:32:12.046200Z

I added info on the renders not working with java 1.8 and quil 3.1.0 on the issue. My guess is that the processing4 branch is where we will see it working first.

👍 1