I've seen situations where #_ still affects the code (or at least allows it
to compile).

reduce expects a function with 2 parameters, one for

If you try to use the #() macro, but only use the first implicit parameter
(%1), it'll blow up with an IllegalArgumentException:

user=> (reduce #(+ %1 1) 0 [1 2 3 5 8])
java.lang.IllegalArgumentException: Wrong number of args passed to:
user$eval--87$fn (NO_SOURCE_FILE:0)

If you add in #_ %2, and it will succeed as the compiler then knows that
it's a 2 argument function:

user=> (reduce #(+ 1 %1 #_ %2) 0 [1 2 6 4 4])
5

(though, really, the intent is clearer if you just define the function with
explicit args)

user=> (reduce (fn [i n] (+ i 1)) 0 [1 2 3 5 8])
5

There might be other situations though where #_ and the thing it "comments"
can still have an impact on how the code executes, just something I ran
across recently that slightly adjusted my thinking on #_.

-Ted

On Tue, Aug 3, 2010 at 2:35 PM, Meikel Brandmeyer <m...@kotka.de> wrote:

> Hi,
>
> Am 03.08.2010 um 16:45 schrieb Yang Dong:
>
> > I've read the src of core.clj of Clojure 1.1.0. Originally I thought
> > the meaning of #_ is to comment the thing after it, sort of like `;'.
> > But the in the src of core.clj in 1.2.0-RC1. The definition of reduce
> > is overrided to use the internal-reduce function. The defn line, is
> > preceded by `#_'. But in 1.1.0, it's not preceded by this reader
> > macro. So, I'm confused...
>
> You are absolutely right. The #_ is kind of comment. And in fact the
> override with the internal reduce function is commented out (ie. it’s not
> active) in 1.2.
>
> Sincerely
> Meikel
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@googlegroups.com<clojure%2bunsubscr...@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 post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to