This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-17
Channels
- # announcements (1)
- # babashka (26)
- # beginners (28)
- # biff (8)
- # calva (45)
- # cider (62)
- # clara (3)
- # clj-kondo (34)
- # cljfx (1)
- # clojure (72)
- # clojure-belgium (1)
- # clojure-canada (13)
- # clojure-conj (2)
- # clojure-dev (3)
- # clojure-europe (19)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-uk (8)
- # clojurescript (10)
- # clr (36)
- # core-logic (13)
- # cursive (2)
- # datalevin (2)
- # datomic (23)
- # fulcro (13)
- # graphql (23)
- # instaparse (1)
- # introduce-yourself (4)
- # jobs (1)
- # jobs-discuss (13)
- # lsp (30)
- # luminus (7)
- # malli (2)
- # off-topic (57)
- # polylith (13)
- # portal (5)
- # reagent (32)
- # reitit (6)
- # remote-jobs (1)
- # shadow-cljs (25)
- # xtdb (12)
In case anyone might find it useful and/or have suggestions for improvement, I've just posted some Calva-based Clojure quickstart instructions, mostly for the sake of a class I'm teaching, at https://discourse.pushlanguage.org/t/clojure-quickstart-instructions/2169. This is aimed at undergrads who've taken just a few computer science courses, have never seen a Lisp, and may not have done much at a command line. Some of my students will have a lot more experience, but I want these instructions to work for everyone. One of my goals was to require as little installation as possible, so this requires just Java, VSCode, and Calva. That makes project creation a bit cumbersome, but I really do want to minimize installations, and maybe it's instructive anyway. I might provide the class with a project template too, with instructions about what has to be changed.
BTW this isn't for a software development course, which is why I'm not expecting that students will know or be focused on learning much about more sophisticated setups or systems issues. This is for a course on Evolutionary Computation that focuses mostly on ideas from AI, machine learning, and evolutionary biology. Students will write and experiment with code for evolutionary algorithms in Clojure, and my goal is to get all of them set up for doing that as quickly and effortlessly as possible, even if they don't have a lot of software development experience or necessarily want to become professional developers.
I will steal a lot of stuff from this resource, @U06BV1HCH 😃 Love it. For the project creation: If people use VS Code for that, then no hidden extensions will be added. If you use something else, opening the project in VS Code is a good way to check if the extensions are right (since that might be tricky to figure out for someone who needs the instructions to watch out for it). Also, for the instructions, it could be nice to show what the project should look like when done. Something like:
.
├── deps.edn
└── src
└── hello.clj
(I should fix so that Calva can help create a minimal project. And remember to use multi-segment structure then.)
Super nice Calva instructions! It's great for me to read a fresh take on it. For the structural editing part you could mention that if you leave strict mode on, alt+backspace/delete
will force-delete when the strict mode prevents it.
For Learning Materials you could mention that the Getting Started REPL in Calva also has an intro to Clojure.Thanks for the great feedback @U0ETXRFEW! I will definitely incorporate a lot of your suggestions. On using VSCode itself for "manual" project construction, would one have to build the folders and files, then close the project folder, and then re-open it for it to be recognized as a deps.edn project? Of course it would fabulous if there was a Calva command that would take a project name and produce the full (minimal) project structure!
In your Clojure resources post you are recommending the command: > Calva: Send current expression (or selection) to REPL window and evaluate it I think it is a better workflow to use Calva: Evaluate Current Form (or selection, if any).
Which reminds me about this in the Quickstart instructions:
> To evaluate an expression in the editor pane: With the cursor in or just after the expression, hold down Option
(or Alt
) key and hit return
(or enter
). Results will appear inline in the editor (but they’re not really in the file!) and also in the REPL pane.
alt+enter
will evaluate the current top level form, not the current form. Someone starting out and learning just one evaluation command should probably learn to evaluate the current form, since you can use it to evaluate top level forms too. So Ctrl
+ Enter
, instead there, I think.
Thanks for spotting that inconsistency with my Clojure resources page. But I'm actually going to keep the suggestion to use alt+enter
in the Quickstart, and also use that on the resources page, because I think that evaluating the top-level form is what students will want and expect. Plus, evaluating non-top-level expressions that use symbols bound in surrounding code break (which makes sense, but it's not pretty). Worst, even when it works "correctly" the results appear inline in the middle of the surrounding expression which I find really disconcerting and I'm pretty confident this will be a source of confusion. I'd actually prefer no results to appear in the editor pane ever -- I think it's odd and confusing since they're "there but not really," and anyway the results are perfectly visible in the REPL window where they belong -- but at least when they're at the end of the expression, it's not too confusing.
It's your prerogative, but at least in the intro you describe evaluate current form, but give the shortcut to evaluate top level form. This might lead to confusion.
Thanks! I think I've now made them both consistent, saying how to evaluate the top level form by using option/Alt+return/enter.
Just answered my own question about creating the project "manually" but from within Calva. You don't have to close and re-open the folder. When jacking in it asks about the project type, and as long as there's a deps.edn
containing at least {}
at that point, it works! 😀 I'm going to mull whether to replace the OS/text-editor instructions with instructions for doing it within Calva
Just made a bunch of updates based on your super helpful suggestions. Thanks!!! The only one I think I didn't take was about deleting in strict mode, which I expect my students to mostly avoid.
> about creating the project "manually" but from within Calva. You don't have to close and re-open the folder. Oh, yes, forgot to answer that one. Glad you just tried it. 😃
Now I tried it myself and notice that I get an error message from clojure-lsp... Until we have fixed that, I don't think it is a good idea to tell beginners to create the project like this. But anyway, in the screen recording you can also see that it is easy to create files with non-existing parent folders with VS Code.
That's great and the video is too! I didn't get the error message... but I'll try again starting from nothing and see if that makes a difference.
If you're fast to type the {}
and save you don't get the error. Maybe tell your students that: ”You have to be very fast!” 😃
@UKFSJSM38 @U9A1RLFNV @U04HKE0BTC5, you know if there is a way we can avoid starting clojure-lsp with an empty deps.edn
(or maybe clojure-lsp could use {}
in that case?).
Not sure I understood the problem, but without a deps file there is no way clojure-lsp knows what command to call to get the classpath
And if it is the first clojure file created, it's appearance will activate Calva and Calva will start clojure-lsp.
Can clojure
take the deps map on the command line? If so when clojure-lsp has read deps.edn and notice it is empty it could pass {}
instead.
We can probably do something in Calva. But it gets a bit delicate since we would need good knowledge about how clojure-lsp will decide to try find the classpath.
Maybe, ATM there is no custom logic to handle or read the files, if we found file X we start process Y
It's pretty easy actually, clojure-lsp just checks this logic: https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/classpath.clj#L170
It's kind of weird, add a intermediate check that would read the file and if inconsistent pass a custom command or so IMO
That explains why I get errors in a project where I have both project.clj and deps.edn and no deps vector in project.clj. 😃
That should not cause errors I guess, if the command works, clojure-lsp would merge both classpaths
Anyway, Calva could solve it, but the problem isn't unique to Calva. Any client that has some auto-start clojure-lsp behaviour would need to solve it. Maybe it is clojure
that should replace empty with {}
... @U064X3EF3?
Can you catch me up so I don’t have to read the thread?
@U064X3EF3 Calva defaults to start clojure-lsp at activation. One activation trigger is that a Clojure file is opened. Creating a deps.edn file in VS Code means that an empty file is first created. clojure
is called by clojure-lsp to figure out the classpath. If the file is still empty by then, the command fails, and the user gets a big error message. In most of these cases, when deps.edn is the first file created, things would work fine if clojure
didn't exit non-zero. Observations:
• If clojure-lsp starts and finds no project files, it will assume default project classpaths (`src`, test
). So a beginner starting out with creating src/hello/core.clj
gets no warnings. (But also no static help with Clojure Core things.)
• If clojure
is run when there is no deps.edn file, it returns the same as if there was a deps.edn with an empty map in it.
The question to you is if clojure
could have a special case for the empty deps.edn file, and treat that the same as if the file didn't exist/contained an empty map?
Can you put it on https://ask.clojure.org and I’ll take a look when I get a chance?
@U0ETXRFEW if there was a Calva command that created the directories and files, and ideally then opened the project, then that would avoid this problem, right? I realize that it'd be good to fix this so that people could build different structures manually from within Calva without getting an error, and that it'd be good to fix the underlying issue that's causing the error for other uses and other tools. But maybe "Calva: Create and open a minimal deps.edn project" would be helpful enough to enough users (particularly beginners) that it be worth doing?
@U06BV1HCH agreed. There's an issue for this. https://github.com/BetterThanTomorrow/calva/issues/1779 In a minimal shape this feature shouldn't be too hard to implement.