functional-programmingclojure

What is the difference between functions and data?


In functional programming, we tend to distinguish between data and functions, but what is the difference?

If I consider a constant, I could think of it as a function, which just returns the same value:

(def x 5)

So what is the distinction between data and a function? I fail to see the difference.


Solution

  • Data

    Function (aka "code")

    Eval


    P.S.

    It occurred to me that the original question has not been fully answered. Consider the following:

    ; A Clojure Var pointing to the value 5
    (def five 5)
    
    ; A Clojure Var pointing to a function that always returns the value 5
    (def ->five  (fn [& args] 5))
    

    and then use these 2 Vars:

    five      => 5
    (->five)  => 5
    

    The parentheses make all the difference.

    See also: