Does Clojure specify the order of evaluation of function arguments?
I.e. When I call a function in Clojure:
(my-func (fun1 arg1) (fun2 arg2) (fun3 arg3))
Is the order of evaluation of fun1
, fun2
, and fun3
defined?
I understand that Java defines the order of evaluation of function arguments as left to right, but I can imagine a functional language like Clojure being more relaxed.
Order of evaluation is left to right. See http://clojure.org/evaluation
Both the operator and the operands (if any) are evaluated, from left to right.
Left to right, but inside out as well (fun1 (fun2 arg2)).
I think that in general for a functional language, you would want to avoid the situation where (fun1 arg1) influences (fun2 arg2) or (fun3 arg3). (fun1 arg1) ideally would return a value without altering the state of existing data structures in your program.
Therefore, depending on how close you keep to a functional programming style, the left-to-right order of evaluation is unimportant.
see http://clojure.org/state
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With