user=> (def s "This is a
multiline string")
#'user/s
user=> s
"This is a\nmultiline string"
user=>
> 2. multiline comments like java
>
> /* this is a
> multiline comment */
I don't know.
> someone who can explain or point
> to relevant info ?
--
Michael Wood <esio...@gmail.com>
Comment blocks are usually done by starting each line with ;;
;; this is
;; a comment
;; block
(some-code)
Anything after a ; is a comment, like python's #. There is a
convention for how many ;s to begin the line with. (Basically ; for
same line comments, ;; for comments above code and ;;; for top-level
comments not commenting on the form below)
There is also the (comment ...) form that disregards the containing
forms. Note that the contents has be well-formed clojure code
(matching parentheses, etc).
(comment ; Usage examples
(foo 1 2 3)
(bar :a :b :c))
// raek
I guess this does not answer the original "why?" question...
Multiline string literals, as showed above, do exist, but do not have
their own syntax. (Also, leading whitespace is not stripped from the
lines.)
Clojure follows other traditions for comments than, for example, Java.
Clojure uses Lisp-style comments, which has followed a separate and
parallel path, but also has the #_ "ignore next form" reader macro and
the comment macro I mentioned before.
// raek
There's also the reader-macro #_, which causes the next form to be
ignored. If you were feeling especially perverse, you could use it to
simulate a mult-line comment:
#_"I have an editor which is too simple to help me
with comments and my right pinky is too tired to type
all those semicolons."
;-)
// Ben
Tradition?
> Multiline string literals, as showed above, do exist, but do not have
> their own syntax. (Also, leading whitespace is not stripped from the
> lines.)
nor in python. a macro to do that on string literals would be neat.
> Clojure follows other traditions for comments than, for example, Java.
> Clojure uses Lisp-style comments, which has followed a separate and
> parallel path, but also has the #_ "ignore next form" reader macro and
> the comment macro I mentioned before.
>
> // raek
>
> --
> 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
(comment This is a
multiline comment?)
Yes. It does, if you plug this into your repl (
user=> (use '[clojure.contrib.str-utils2 :only [split-lines join]])
user=> (defn ml-str
"Scala style multiline string"
[s]
(let [l (split-lines s)]
(join "\n" (map (fn [b]
(let [i (.indexOf b "|")]
(if (> i 0)
(.substring b (inc i))
b))) l))))
#'user/ml-str
user=> (ml-str "Hello World
|the margin will
|be deleted as per
|the request of scala
|users")
"Hello World\nthe margin will\nbe deleted as per\nthe request of scala \nusers"
user=>
> For comments, there's (comment This is a comment ...). I'd say that
> eliminates the need for /* ... */.
Except that with (comment ...) the stuff in ... has to have balanced parentheses (& possibly meet other constraints since it's being parsed?).
I'm finding that ;, #_, and (comment ...) generally suffice but every once in a while I do miss having block comments (like /* ... */, or Common Lisp's #| ... |#), e.g. when I want to comment out a big chunk of partially-written code that may not be balanced, or when I have a real comment that includes partial bits of code that may not be balanced.
-Lee
--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspe...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438
Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/
this, and my earlier rhetorical question about having this kind of
thing as a macro as produced: http://gist.github.com/527621
// Ben
Am 16.08.2010 um 21:13 schrieb Lee Spector:
> I'm finding that ;, #_, and (comment ...) generally suffice but every once in a while I do miss having block comments (like /* ... */, or Common Lisp's #| ... |#), e.g. when I want to comment out a big chunk of partially-written code that may not be balanced, or when I have a real comment that includes partial bits of code that may not be balanced.
Every descent editor should provide a comment-selected-text functionality. So whether multiline comments or single comments are used should be an implementation detail. You also have to get (* *) (OCaml) nested and with /* */ (C) you are in trouble anyway because they can't nest. So I don't think that multiline comments are so much better without editor support. (I wrote a plugin for Vim which does the required escaping. Believe me: Single comments are much better!)
Sincerely
Meikel
Yeah, I realize there are problems with nesting and so in CL I generally use #|...|# only to comment out big blocks, and ; for everything else.
I've worked in several editors that have comment-selected-text, but I don't see it in Eclipse/Counterclockwise, which is what I'm using now for Clojure -- does anyone know if it's there and I'm just missing it?
Not that I think this is any kind of major issue, but as I said I do sometimes miss syntax-ignoring block comments (or comment-selected-text, which I agree is just as good and maybe better sometimes).
Right, but what should be done, then? The command is a "toggle", but
there are both commented and uncommented lines: should it comment all
lines, or uncomment all lines?
2013/6/29 Niels van Klaveren <niels.va...@gmail.com>:
> In my version of CCW CTRL-/ multiline (un)commenting just works (underRight, but what should be done, then? The command is a "toggle", but
> Windows).
> Perhaps it's a keyboard shortcut problem ?
>
> Only problem there is when multiple lines are selected, and some are
> uncommented, uncommenting the whole block doesn't work.
there are both commented and uncommented lines: should it comment all
lines, or uncomment all lines?