expr in comment not ignored?

5 views
Skip to first unread message

klang

unread,
Oct 14, 2009, 7:37:40 AM10/14/09
to Clojure
Somehow, namespaces are resolved by the REPL, eventhough they are
inside a comment.

;;The following can be executed line by line in a REPL

;; resolves symbol in the current namespace
(comment ::bar)

;; resolves symbol in namespace foo
(comment ::foo/bar)
;; that is illegal (foo does not exist, indicating that the body of
comment is _not_ ignored?)

(ns foo)
;; create namespace foo and it becomes legal
(comment ::foo/bar)

;; Usage for this specific way to comment:
;; Telling a user how to use foo from somewhere else if the path to
foo is anoyingly long
(comment
(alias 'fii 'foo)
::fii/bar)
;; No, this will not work, as fii does not exist, as the alias fii
does not exist in namespace foo and it shouldn't as this is just a
helpfull comment for the user of the namespace.

;; solution. when defining a namespace, remenber to make an alias to
the namespace if you want to make a comment using local symbols

;; file foo.clj containing
(ns foo)
(alias 'fii 'foo)
;; <loads of really cool code>
(comment
alias 'fii 'foo
::fii/bar)
;; end


So, my question is .. is this an error or a feature .. or should I
just use ;; for comments?

/klang

Meikel Brandmeyer

unread,
Oct 14, 2009, 8:04:24 AM10/14/09
to Clojure
Hi,

comment is a macro, which simply throws away its contents. But since
the namespace-qualification of symbols and keywords happens in the
reader, it is already too late. I would recommend to use ; for
comments.

Sincerely
Meikel

klang

unread,
Oct 14, 2009, 10:18:52 AM10/14/09
to Clojure
Well, I can accept that. Thak you for clarifying.

Faithfully,
Karsten Lang
Reply all
Reply to author
Forward
0 new messages