3 ms·
It's alternate syntax, or, if you want to go there, you can say it's syntactic sugar. Take a few minutes to go read the bytecode Java generates on something li
by chchrutuch 11y ago
It's alternate syntax, or, if you want to go there, you can say it's syntactic sugar. Take a few minutes to go read the bytecode Java generates on something like person.getName() to see how this is being handled at that level.
Further, purity is about expectations, not scope. Expecting something to be pure means I can reliably call it with the same arguments and always get the same result, with the additional expectation that it will change nothing about the world. A function that accepts no arguments can be pure but must always return the same thing. If the person's name is indeed immutable, then person.getName(), provided it performs no side effects, is perfectly pure.
In concept, other than brevity, invoking a constructor on an immutable object is not much different than the function returned by a higher order function such as this:
(defn name-getter [{name :name}] (fn [] name))
(def get-name (name-getter {:name "John"}))
(get-name)