Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

"You tripped the alarm! nth is bad!" - but I did not use it #107

Open
srid opened this Issue Sep 17, 2011 · 4 comments

Comments

Projects
None yet
3 participants
Contributor

srid commented Sep 17, 2011

  1. Go to http://4clojure.com/problem/21#prob-title
  2. Enter (fn n-th [[x & xs] n] (if (zero? n) x (n-th xs (dec n)))) as the solution
  3. Click 'Run'

Error You tripped the alarm! nth is bad! is printed.

But I only used n-th, not nth.

(Changing n-th to foo didn't have any effect)

Contributor

srid commented Sep 17, 2011

This worked, though:

(fn foo [l n] (if (zero? n) (first l) (foo (next l) (dec n))))

So using destructuring in function arguments is not allowed?

Owner

amalloy commented Sep 18, 2011

user> (clojure.walk/macroexpand-all '(fn [[x]] x))
(fn* ([p__2058] (let* [vec__2059 p__2058 x (clojure.core/nth vec__2059 0 nil)] x)))

Note the nth in the expansion. There's a similar problem with using for in the "Count a sequence" problem, since for expands to a use of count.

Owner

amalloy commented Sep 18, 2011

If someone can find a good way to make this clear to users, though, I'd be delighted. We've had to answer this question a few times before.

Owner

dbyrne commented Sep 19, 2011

Maybe add something to the "Help" page describing this issue and then link to it from the error message. Not a perfect solution, but its a quick fix and should help alleviate some confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment