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

I'm a Python user and I love Clojure. I guess I missed the Go bus. But there's 2 things about it I'm not too fond of.

One is due to it's declarative nature (which I love), it's quite difficult to get up to speed with unfamiliar code.

The 2nd is due to it's JVM roots. Those stacktraces, man. And when it happens on an anonymous funtion in a not so documented library, ugh. It's like hitting a brick wall.

The first, I can deal with enough practice and Schema/core.typed. Is there any hope for the stacktraces to improve? How do other JVM based languages fare in this regard?




Oddly enough I never used this, but maybe named fns might help? (http://clojure.org/special_forms#Special%20Forms--%28fn%20na...)

    (fn my-name []
      (throw (Exception. "boom")))
(Sorry, I don't know Clojure internals well enough to have great answers to your explicit questions.)

[Edited: thanks to jerf for pointing out the inconsistency in a term I used.]


Named... anonymous... functions? Wuzzah fuzzah?


They allow you to use recursion without the need for a Y-combinator.


Yeah, that's a terminology issue. They mean lexically scoped named functions. Versus the default in Clojure of global or namespace scope.


Just like in Javascript.


Named anonymous functions are there to allow you to call the function recursively while inside it.

i.e.

    (= ((fn factorial [x] 
          (if (<= x 1) 
              1 
              (* x (factorial (dec x))))) 5)
     120)
Note, this isn't run under TCO (see loop/recur).


Also, in your example, the recursive call is not in tail position. You would first need to rewrite it to use an acumulator parameter.


There are people working on improving stack traces[1][2], but there is no standard solution yet.

[1] https://github.com/AvisoNovate/pretty

[2] https://github.com/mmcgrana/clj-stacktrace




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: