Hacker News new | comments | show | ask | jobs | submit login

I am very new to Clojure and only semi-experienced in CL, but I ran into a problem today that left a pretty bad taste in my mouth. I had something like:

  (defn foo [bar]
    (let [whatnot (+ bar 3)]
      (frobnicate whatnot)))
  
  (defn frobnicate [quux]
    (println "Hello" quux))

And it threw an error, since frobnicate hadn't been defined while it was dealing with foo. But I didn't know that. And using and commenting out my (ns spam.core)--and trying various compilation incantations with SLIME--were confounding variables such that the call to frobnicate sometimes worked if the ns call was removed and you held your nose right. Finally I gave up and posted to Stack Overflow, thinking I'd jacked up my namespace somehow. Instead they told me to either move frobnicate's definition to be above foo, or else declare it.

It never occured to me that a modern, not-low-level well-received language would have this limitation. And I feel like I'm part of the target demographic for Clojure. I'm an experienced Java and Python coder. I know and like Lisp. I'm interested in learning a new language. And I did what I thought I was supposed to--I read the list of differences between Clojure and other Lisps on the official site. I read a tutorial that concisely addressed Clojure syntax, data structures, special forms and so forth in a way designed for people who already knew how to program.

And there's a lot of things I like--better data structures, the lambda reader macro, the judicious use of brackets to avoid paren soup, Java interop, and more things that I'm only discovering as I gain more experience.

But I'm still kind of in shock about having to declare methods. A completely unexpected wart.




There are two warts - having to declare methods, and the obscure error message. A smart error handler could have seen that frobnicate had been defined further down, and told you exactly how to fix it. And it would be ok when that error handler didn't work in the REPL.


Agreed. Here's the exact error message I got:

  error: java.lang.Exception: Unable to resolve symbol: frobnicate in this context
So I really thought I'd misspelled it or messed up my namespace or just broken the compiler :/




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: