I'm not sure if anyone's done this before, but I'm fed up with writing code that looks like this:
I didn't realize you could bind to empty identifiers like that. Alright, that makes more sense. I figured I was missing something.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not encouraged in Clojure, and rarely needed. Certainly
sometimes it's the best way to do something, but not so often that I'd
become frustrated; if anything, having to write such irritating code
can serve as a good reminder that I shouldn't have so many
unrestrained side effects scattered through my logic.
(-> ((fn []
(let [a 1]a)))
(println "this is a: " a)
((fn [a]
(let [b 2](list a b))))
(println "this is b: " b)
((fn [[a b]]
(let [c 3](println "Sum: " (+ a b c))))))
(println "this is c: " c)
(defmacro dbg[x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
When you use def inside a defn is it equivalent to a let binding like this?
(defn foo []
(def a 1)
(println a))
(defn foo []
((fn [a]
(println a)) 1))
Anyone voted for internal define lately?
On a side note, I was partially inspired by Haskell's do notation, which is imperative-looking syntactic sugar for monadic bind operators.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
When I want to add print commands for debugging, I usually either do it the way David Nolen described, i.e., binding _ to a printf statement, or I use a little utility macro like this (picked up from stackoverflow):(defmacro dbg[x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
FWIW, when just wanting to print out debug values, I use a custom reader tag similar to the above macro:(let [x #log/spy (+ a b)](usage-of x))
(defn emit-dbg [form] ...))
For the situation where the lets are nested because you're checking the values in some way after each binding, I wrote a macro called let?. I find it very useful and use it in nearly all my code. https://github.com/egamble/let-else