On Jan 10, 12:03 pm, Erlis Vidal <er...@erlisvidal.com> wrote:
> Hi,
>
> I'm solving the following exercise and when I'm trying to use the answer:
>
> #(reduce + (for [x coll] 1))
>
> I get the error saying that I was using "count" which I'm not. Someone
> knows why is that? Is this a bug in 4Clojure or something in the language
> that I cannot see?

Like Jack Moffitt suggested, for uses count. A handy tip: you can
check the source of a function or macro in a repl using clojure.repl/
source:

(require 'clojure.repl)
(clojure.repl/source for)

;(defmacro for
;  "List comprehension. Takes a vector of one or more
;   binding-form/collection-expr pairs, each followed by zero or more
;   modifiers, and yields a lazy sequence of evaluations of expr.
;   Collections are iterated in a nested fashion, rightmost fastest,
;   and nested coll-exprs can refer to bindings created in prior
;   binding-forms.  Supported modifiers are: :let [binding-form
expr ...],
;   :while test, :when test.
;
;  (take 100 (for [x (range 100000000) y (range 1000000) :while (< y
x)] [x y]))"
;  {:added "1.0"}
;  [seq-exprs body-expr]
;  (assert-args for
;     (vector? seq-exprs) "a vector for its binding"
;     (even? (count seq-exprs)) "an even number of forms in binding
vector")
; <rest of code elided>

You can see that the last line above calls count. My guess is that
since for is a macro, it gets expanded and the 4clojure engine sees
the count function and trips the alarm.

-- 
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