News for hackers. Stuff that matters.
Re:Rich Comment Blocks in Clojure by manishsharan on Friday October 09, 2020 @01:59PM (#24732576)
Its not all roses; I tried to comment out a few routes in my clojure compojure code by doing something like this to my code a while back.

  (defroutes data-routes
  (GET "/something1" []  (sample-json-data))
  (GET "/something2" []  "hello1")
  (comment 
  (GET "/something3" []  "hello3")
  (GET "/something4" []  "hello4"))
  GET "/something5" []  "hello5")
)

Then when a client tried to access /something5 , I began getting null pointer execptions. This took me a while to figure out what I had done wrong.

Re:Rich Comment Blocks in Clojure by bjoli on Friday October 09, 2020 @03:31PM (#24733534)
Common mistake. For non-lispers: Macros evaluate from the outside, which means the defroutes macro will expand before the (comment ...) macro. For this to reliably work, you need a reader macro that removes the code before macro expansion. I don't know if clojure has that, but common lisp and some schemes have utilities for it.
Re:Rich Comment Blocks in Clojure by nimih on Friday October 09, 2020 @03:33PM (#24733550)
The comment macro should really come with a warning that it should only be used as a top level form. Using it inline (a very natural thing to do if you're coming from a language with more typical block comments!) only ever leads to suffering, in my experience.
Re:Rich Comment Blocks in Clojure by Borkdude on Friday October 09, 2020 @02:29PM (#24732880)
In that case you should use a reader ignore:

#_(GET "/something3" [] "hello3")

Re:Rich Comment Blocks in Clojure by nimih on Friday October 09, 2020 @03:49PM (#24733718)
The reader ignore macro can be stacked in clojure, so you can also do

    #_#_#_#_GET "/something3" [] "hello3" 
if it strikes your fancy. The possibilities for bikeshedding here are truly remarkable.
Re:Rich Comment Blocks in Clojure by clojurenoob on Friday October 09, 2020 @03:16PM (#24733382)
I notice I accidently do similiar thing with parenedit. I can accidently move forms in and out of where they should be. Not an issue if the functions are small but with longer ones I might slurp off screen.
Re:Rich Comment Blocks in Clojure by hombre_fatal on Friday October 09, 2020 @09:27PM (#24736028)
I notice default syntax highlighting in Emacs, Vim, and VSCode make that odd-one-out "GET" a different color than the rest which would make this a lot easier to catch than otherwise.