A drawback of the less-parentheses approach

184 views
Skip to first unread message

Taegyoon Kim

unread,
Jun 9, 2014, 10:07:42 PM6/9/14
to clo...@googlegroups.com
I once liked the Clojure's less-parentheses approach.
 
Today I found that you can't utilize s-expression comments easily in Clojure.
 
e.g.
In
(let [x 1 y 2] x)
When you are about to comment out the "y 2" part, you have to move the cursor back and forth to insert new parentheses.
 
And you can't do this:
user=> (let [x 1 (comment y 2)] x)
 
IllegalArgumentException let requires an even number of forms in binding vector
in user:1  clojure.core/let (core.clj:4043)
 
(comment) in Clojure is not really comment. It returns nil. http://clojuredocs.org/clojure_core/clojure.core/comment
 
vs.
 
You can do this in Racket:
> (let ([x 1] #;[y 2]) x)
1
 
#; is s-expression comment in Racket.
 
Parentheses are there to group logically related things together.
 

guns

unread,
Jun 9, 2014, 11:22:50 PM6/9/14
to Taegyoon Kim, clo...@googlegroups.com
On Mon 9 Jun 2014 at 07:07:42PM -0700, Taegyoon Kim wrote:
> And you can't do this:
> user=> (let [x 1 (comment y 2)] x)

Alex Miller (?) once pointed out that the #_ reader macro can be chained
like this:

(let [x 1 #_#_y 2] x)

Pretty nifty.

guns

Sean Corfield

unread,
Jun 9, 2014, 11:24:52 PM6/9/14
to clo...@googlegroups.com
On Jun 9, 2014, at 7:07 PM, Taegyoon Kim <stelo...@gmail.com> wrote:
And you can't do this:
user=> (let [x 1 (comment y 2)] x)

You can, however, do this:

user=> (let [x 1 #_(y 2)] x)

and this:

user=> (let [x 1 #_y #_2] x)

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)



signature.asc

Taegyoon Kim

unread,
Jun 10, 2014, 12:22:10 AM6/10/14
to clo...@googlegroups.com, stelo...@gmail.com, se...@sungpae.com
Ah, reader macro! Thanks!
 
Ignore next form (#_)
The form following #_ is completely skipped by the reader. (This is a more complete removal than the comment macro which yields nil).
 
 
Conclusion: Don't use the comment macro. It makes runtime overhead.
 

2014년 6월 10일 화요일 오후 12시 22분 50초 UTC+9, guns 님의 말:

Alex Miller

unread,
Jun 10, 2014, 1:01:20 AM6/10/14
to clo...@googlegroups.com, stelo...@gmail.com, se...@sungpae.com
The only place I've found the comment macro to be useful is at the top-level of a ns to hold a bunch of test/temp code.

Karsten Schmidt

unread,
Jun 10, 2014, 5:19:08 AM6/10/14
to clo...@googlegroups.com, stelo...@gmail.com, se...@sungpae.com
Also, if you write your let bindings (according to common convention)
so that you have one binding per line, you can use ;; to create a line
comment, like:

(let [x 1
;;y 2
]
x)

(Ps. A single semicolon would suffice, but the double version keeps
indentation when formatting the buffer in Emacs (and other editors))
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Karsten Schmidt
http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk
Reply all
Reply to author
Forward
0 new messages