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

Maybe this:

    (let [a 10
          a (+ (let [a 20] a) a)]
     a)
The thing is you can't refer to the resulting compilation, there is a correspondence between CPS and SSA, and SSA lets the JVM better optimize things.

Let me try and better explain myself. For me, the qualification here is that the form exhibit semantics that are compatible with functional programming, and can be evaluated using a lambda calculus computational model. Those semantics are in turn incompatible with the imperative ones, since it prevents you from doing some things that imperative semantics would allow, as I demonstrated with my prior example.

The let form does dictate a series of expressions to be executed sequentially from top to bottom, but the binding of their result to a name is done functionally, not imperatively.

This still models a data-flow, and the fact it lets you shadow prior names doesn't change the functional nature of it.

The form simply expresses a composition of functions and how their inputs/outputs connects.

That means it doesn't actually require any separate mutable memory location, even if the Clojure implementation for it might use some.

That's inherently the conceptual model of a functional computation, and it is not that of an imperative one.

    (let [a 1
          b 2
          a (+ a b)]
     a)
Models a data-flow that you can think of as a multitree:

      1   2
       \   \
    (+,   ,   )
     \
      3
What that means is you never need the variables, they are simply a syntactic convenience, in fact that's why they are not called variables but bindings, they are simply syntactic labels, there is no real requirement to have a seperate memory location that sequential instructions will be allowed to mutate. So how I see it, that fact makes it functional, and not imperative.

If you look at the multitree, at each level of the multitree, you are free to evaluate the nodes in any order, but if there is an input/output dependency, then you must guarantee that ordering.

At the end of the day, we could argue forever that we just have different taxonomies. I consider imperative programming the computational model where you give instructions in sequence which dictates mutations on memory locations.

I consider functional programming the computational model where you declare a composition of expressions that can be reduced using variable substitutions.

With this in mind, let qualifies as a functional construct, because it defines such a composition and can be reduced through substitution.

Now in practice, the Clojure let form reduces over this sequentially both left to right on a per-form basis, and top/down between each pair of bindings. And since Clojure allows you to mix imperative anywhere, you can have a println in it and know that it'll run after all that came before, and before all that comes after. But semantically it is still functional. And that's why you can't modify the bindings, because they do not conceptually represent memory locations which you can mutate.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: