4 ms·
An immutable mark will allow the optimizer to constant-fold an expression that contains only IMMUTABLE operations. It basically has to believe you on this one,
by fdr 13y ago
An immutable mark will allow the optimizer to constant-fold an expression that contains only IMMUTABLE operations. It basically has to believe you on this one, and being wrong is not good at all.
STRICT is less advisory: if specified, the function will not be evaluated if it any NULL is seen in the argument list (NULL will be yielded immediately), without ever passing control to the code in the function.
- ithkuil 13y agowell, beside optimization, a function marked immutable is important because indexing on function return values makes only sense if the function is idempotent.
- victorNicollet 13y agoIdempotent is probably not what you meant. It makes sense to index on, say, `reverse(name)` (to perform suffix searches), and that function is immutable and deterministic, but it is not idempotent (except on palindromes).
- ithkuil 13y agowow, there seems to be a degree of confusion about this term, depending on the context. Mathematically speaking it means that you can apply it multiple times and get the same result, i.e. reverse(reverse(name)) == reverse(name)" However, I heard it using it many times where the correct term would be "pure function" (one whose output is defined solely by its input). But this is clearly misleading. I guess that the confusion stems from the use of "applying multiple times". Formally multiple function application means f(f(x)), and not simply repeating function evaluation f(x); f(x). Furthermore I saw people distinguishing "side effect idempotence" (observed by all pure functions) and "return value idempotence". To add more confusion to that, some some HTTP (GET/...) operations are called idempotent, even though it's clearly not in functional sense (if you take the output of the GET and feed it as argument to another GET, you won't get the same result again), but only meaning "side effect free".