Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could Clojure do without let?

Tags:

clojure

I find I very rarely use let in Clojure. For some reason I took a dislike to it when I started learning and have avoided using it ever since. It feels like the flow has stopped when let comes along. I was wondering, do you think we could do without it altogether ?

like image 975
Hendekagon Avatar asked Nov 28 '12 23:11

Hendekagon


2 Answers

You can replace any occurrence of (let [a1 b1 a2 b2...] ...) by ((fn [a1 a2 ...] ...) b1 b2 ...) so yes, we could. I am using let a lot though, and I'd rather not do without it.

like image 174
Cubic Avatar answered Sep 22 '22 21:09

Cubic


Let offers a few benefits. First, it allows value binding in a functional context. Second, it confers readability benefits. So while technically, one could do away with it (in the sense that you could still program without it), the language would be impoverished without a valuable tool.

One of the nice things about let is that it helps formalize a common (mathematical) way of specifying a computation, in which you introduce convenient bindings and then a simplified formula as a result. It's clear the bindings only apply to that "scope" and it's tie in with a more mathematical formulation is useful, especially for more functional programmers.

It's not a coincidence that let blocks occur in other languages like Haskell.

like image 29
RonaldBarzell Avatar answered Sep 24 '22 21:09

RonaldBarzell