TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Critiquing Clojure

60 pointsby sjbachalmost 16 years ago

6 comments

pmjordanalmost 16 years ago
A lot of these are personal preference and borderline traditionalist, and as pointed out by others, the dynamic binding one is in fact not strictly true.<p>One thing that <i>does</i> however bother me about Clojure is the interaction of dynamic binding and lazy evaluation. Allow me to illustrate:<p><pre><code> =&#62; (def *test* 0) #'user/*test* =&#62; (binding [*test* 2] (map #(* % *test*) '(1 2 3))) (0 0 0) </code></pre> The call to <i>map</i> is lazy, and the returned seq is only evaluated once it hits the 'P' of REPL, which is outside the dynamic binding of <i>test</i>. If you surround the <i>map</i> call with <i>(doall</i> and <i>)</i>, the result is (2 4 6).<p>This is of course a trivial case, but I've been bitten by this in practice where the binding, lazy sequence and var evaluation were a few call steps apart, and it's always been very unpleasant. Most of the time, it's involved vars which don't have a root binding, so it throws an error, but in other cases it's a lot more serious.<p>I guess the same problem can be provoked in both Clojure and CL by returning a closure evaluating that var to back outside the dynamic binding, but since you'd be explicitly invoking the closure, it's a lot more obvious what's going to happen than the "magic" that is lazy evaluation.
febelingalmost 16 years ago
I was interested in Clojure before, but the critisism I found in the two recent posts here on HN make it even more interesting. I feared something substantial might turn up that really defies using it, but to the contrary: if issues listed in the blog posts are the biggest problems people find with Clojure, then that is quite promising.
评论 #670059 未加载
radu_floricicaalmost 16 years ago
I don't have much experience in CL, but I started to really like the fact that clojure is Lisp 1. When I have a hash map "client", I can use all three:<p>(get client :phone)<p>(:phone client)<p>(client :phone)<p>It takes some getting used to, but I already came to expect (and enjoy) that any symbol I use can be a function.
评论 #669021 未加载
评论 #668915 未加载
twopoint718almost 16 years ago
On #5, the code isn't doing what the author may think:<p><pre><code> (let [#^int a 2 #^int b 3] (cons a b)) </code></pre> <i>a</i> and <i>b</i> are not hinted to be primitive types. Type hinting is purely for objects. Use hinting to make it clear to the compiler what sort of <i>objects</i> you are passing into something (e.g. a constructor that takes a String). If there is confusion, clojure will do reflection.<p>The right thing to do in this case, is the second thing that the author mentions:<p><pre><code> (let [a (int 2) b (int 3)] (cons a b)) </code></pre> a way to see that <i>a</i> and <i>b</i> are really primitive is:<p><pre><code> (let [x (int 5)] (.shortValue #^Integer x)) ; exception: "can't type hint primitive..." </code></pre> There's a post on the mailing list that goes over this much better than I did (and where I drew the examples): <a href="http://groups.google.com/group/clojure/browse_thread/thread/b0554f7381b8db96/74bf85fabc12761a" rel="nofollow">http://groups.google.com/group/clojure/browse_thread/thread/...</a><p>I understand that this is really beside the point, that the author finds type hinting syntax unattractive, but I just wanted to clear up confusion (if there was any).<p>EDIT: clarity
mmcgranaalmost 16 years ago
I'm not familiar with CL's "PROGV", but you can indeed dynamically rebind vars at runtime with Clojure: <a href="http://paste.lisp.org/display/73551" rel="nofollow">http://paste.lisp.org/display/73551</a>
plinkplonkalmost 16 years ago
#2, "Functions must be declared before first call",is very irritating (to me) It feels like I am back in Pascal land
评论 #668883 未加载