Problem #22 - I'm tripping the alarm for 'count' but I'm not using 'count'

81 views
Skip to first unread message

Matthew Farabaugh

unread,
Dec 14, 2019, 4:42:56 AM12/14/19
to 4Clojure
#(reduce + (for [_ %1] 1)).

Matthew Farabaugh

unread,
Dec 14, 2019, 10:33:17 AM12/14/19
to 4Clojure
I should have just included the problem here to reduce hassle for the potential user gracious enough to help me:

22-easy-find-number-of-members-without-count.jpg

Leif

unread,
Dec 17, 2019, 12:31:50 AM12/17/19
to 4Clojure

Hi, Matthew.

The problem is that 4clojure seems to macroexpand your code before checking it, and `for` is a macro that uses `count` internally.  This is a pretty subtle problem for newcomers to run into, especially since lisp macros are unlikely to be familiar.  But we have to work with the website as-is, I suppose.

Your solution should work if you rewrite it to use `map` instead of `for`.

Happy hacking,
Leif

Matthew Farabaugh

unread,
Dec 25, 2019, 10:18:13 AM12/25/19
to 4clo...@googlegroups.com
Hi Leif,

I'll keep what you said about macros in mind if something like this happens again. Just another learning opportunity.

Thanks,
Matt F

--
You received this message because you are subscribed to the Google Groups "4Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 4clojure+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/4clojure/d074aa2a-c16e-4fd6-8a1b-0302cac28336%40googlegroups.com.

Alexey Perekhodov

unread,
Jan 23, 2020, 11:23:09 AM1/23/20
to 4Clojure
Then maybe the use of 'for' should also be restricted for this problem.
Reply all
Reply to author
Forward
0 new messages