TIL: C-c C-c works with #_(+ 1 1)
I was watching https://www.youtube.com/live/kGOB9IPKHfo?si=l3a2FuDsSGamd9Ha&t=394 and @neumann was showing his setup. I used to use (comment ...) but this is better IMO. 🎉
> this is better IMO
Only for single forms. Because you have to add it in front of each form.
Or use #_#_#_ with the number of #_ being equal to the number of forms you want to comment out. :)
Indeed.
if in emacs, there’s a way to make all of that stuff work with comment forms: https://github.com/clojure-emacs/clojure-mode/blob/master/clojure-mode.el#L2365-L2372
then the “top level” type functions will ignore the comment form and treat the first level forms as top level there
@dpsutton I didn't know. It looks promising.
it’s deeply ingrained in my workflow now. enjoy it!
I use #_ instead of comment. It works better for me.
Because it can be used like shown here, for precise inner disablement, or you can wrap it around a big thing similar to comment but it's shorter
I use both #_ and comment. If I just have a few items, I tend to use the ignore next form (`#_) for each item. If I have a group of items, I tend to use comment`. I really like both of them.
As @didibus mentioned, you can use ignore in the middle of things, and that is really useful too.
yes didn’t want to say #_ has no place. use it quite a bit. and its distinct from comment for my purposes. i just wanted to highlight that C-c C-c and friends work with the comment macro with a tweak as that seemed to be what was so compelling about the reader discard version
For example, I was working on a regex, and I cranked out a few different test cases as I was writing the function. I just co-located them like so:
(def comment-re #"^\s*;.*")
#_(re-matches comment-re "; test")
#_(re-matches comment-re " ; test")
#_(re-matches comment-re " ;test")
Those turn into tests later on, but it was quick to just add them right under the definition as a quick sanity check for what I was doing. I started with one, so I used #_, and then I copied and pasted that line a couple times and modified it.ha. i do that but with a single comment form and not 3. but same workflow
For some reason, when I have a "process", I tend to use a comment block. Eg.
(defn start-server
[config]
(jetty/run-jetty (app config) {:port (:dev/port config) :join? false}))
(comment
(def server (start-server (config)))
(.stop server)
(.start server))i have a keybinding to create a comment block after the top level form i’m in so that drives my usage quite a bit
The more related things I put together, the more likely I am to use a comment block, but a lot of my stuff starts with the ignore form.
(defun personal/insert-comment ()
(interactive)
(end-of-defun)
(insert "\n")
(insert "(comment\n )\n")
(clojure-backward-logical-sexp)
(forward-char 1)
(clojure-forward-logical-sexp)
(insert "\n")
(indent-according-to-mode))
and bound to C-M-i and puts my cursor right there ready to goNice!
You can also just do:
#_(
(def server (start-server (config)))
(.stop server)
(.start server)
)
No need for comment.
And what I like to do:
#_(do
(def foo 1)
(def bar 2)
)
Now you can eval the whole thing in one go, or each form individually.That would require either selecting the exact form or using some "eval the current form only" mechanism, which demands a great care of positioning your cursor.
With (comment ...) or #_-per-form, every form is top-level, so you can just use "eval the current top-level form", which doesn't ask for any care or explicit selection.
Inbgeneral Inuse the reader macro comment to help debug specific parts of existing code. I use the comment form for Repl driven development, separating experiments from code designs I have chosen to use https://practical.li/clojure/reference/clojure-syntax/comments/
@p-himik You don't use structural navigation? It's pretty easy to select the correct form I find. In fact I never use the eval-top-level command because I find it redundant compared to just selecting the top level form and evaling it.
Even with structural navigation, selecting a form you have just navigated to is still an extra step, isn't it?
You don't need to select it, just have the cursor on it. At least in Emacs.
Ah, I didn't even realize Cursive also had "Send Form Before Caret to REPL".
What is your recommendation for learning web development with Clojure to create full-stack applications, given that the book "Web Development with Clojure" is outdated?
I found this article very helpful: https://www.evalapply.org/posts/clojure-web-app-from-scratch/index.html
Another article with a wide variety of options is <https://clojure-doc.org/articles/ecosystem/web_development/>, although it's a bit more "here are libraries that are web/web-adjacent", but some of those libraries (e.g. Kit and Biff) will have tutorials regarding their specifics.
I’d say give the caveman guide a try https://caveman.mccue.dev/ If you already know web development, this is what you’re looking for, a guide on how to setup your project, it gives you a structure that is easy to understand, scale and reproduce later
Thank you so much @reginaldo.junior696! That was exactly what I needed!!! (I come from Rails world)
Glad to hear bro! I was enlightened by this same guide about a month ago, just passing the word forward 🙏
I recommend reading https://github.com/nextjournal/calendula/ and https://github.com/nextjournal/impulse. Two Clojure files of 130 lines each, that you can understand in full. The result is a working Calendly clone with login and email (with the help of libraries). Caveman is a great introduction to "the common way of doing things", calendula / impulse asks whether maybe we can go simpler.
@teodorlu from what I understand application.garden is not publicly available yet, is that correct?
It's not yet generally available — but if you ask in #application-garden, you might very well have access before the day is over!
great, thanks!