On the arbitrariness of truth(iness)

jnz/jz are very useful for pointers.

if p = function_with_optional_result(...)
    # use p, as it is non-null
end

is a common pattern in, for example, the LLVM code base.

I’m not saying this is a better convention than explicit optional types (or returning nothing that’ll throw an error if you try to use it as a pointer), but it’s still fairly convenient.

Ptr types may not be integers, but it’s fairly reasonable to have them behave the same way, and thus have truthiness of integers also be based on comparison to zero.
I don’t know the history, but this also fits the pattern of C vs Lisp having settled on different conventions of truthiness for integers.

1 Like