One of the important things to note though is the evaluation model. or
short-circuits, therefore: (or true :some random expression that never gets evaluated:)
never evaluates the last. or
is traditionally used as much as a control structure as a 'logical or'.
In the traditional model of (f x y z)
, x, y, and z are evaluated, and f is applied to them.
In the use of (apply f vec)
the contents of the vector are not evaluated, they are taken as is. This is most clearly visible with a vector of symbols, they do not evaluate in this context to their bindings. However, this is obfuscated by the fact that Clojure's model for vector creation is some-what different then other lisps, [a b c d]
yields a vector which contains the evaluations of the symbols a
, b
, c
, and d
. Contrasting most Lisps, wherein #(a b c d)
does not evaluate the symbols, and just is identical to evaluating (vector 'a 'b 'c 'd)
(or in fact (apply vector '(a b c d))
).
So even if it were possible to apply special syntactic forms, it's result would have an opaque semantics. or
first evaluates its first argument, if true, it stops and returns that, else it goes to the second and repeats until at the last. In the case of apply, the arguments are already all evaluated, should it then evaluate some a second time? Most likely resulting into a runtime error along the way?
From an implementation perspective, it would be very performance enhibative if syntax was were also 'objects' and would require a much more complex evaluation model. So they are not resolved at runtime, but rather rewritten to compiler primitives at compile time.
But, for this very reason, when or
is used logically rather than as a control structure, I myself find it handy to have functions or/f
, and/f
, if/f
, et cetera available which are true procedures and evaluate all of their arguments and thus can be applied.