It’s only vague if coming from a language where it’s invalid or vague semantically. For example:
Javascript - [] is truthy for whatever reason
C - int x[] = {}; evaluates to true because it’s a pointer; C only evaluates to false if something is 0
Rust - invalid because you cannot convert a vec -> bool directly, and there’s no concept of null (same w/ Go, but Go has nil, but requires explicit checks)
Lua - empty tables, zero, and empty strings are truthy; basically, it’s truthy unless it’s nil or false
The only surprising one here is Javascript. I argue Lua and Python make sense for the same reason, Lua just decided to evaluate truthiness based on whether the variable is set, whereas Python decided to evaluate it based on the contents of the variable. I prefer the Python approach here, but I prefer Lua as a language generally (love the simplicity).
I did not say it’s not semantically well defined.
https://en.wikipedia.org/wiki/Brainfuck#Hello_World! – this is semantically well defined, but it’s still vague. Vagueness is a property of how well the syntax is conveying intent.
It’s only vague if coming from a language where it’s invalid or vague semantically. For example:
[]
is truthy for whatever reasonint x[] = {};
evaluates to true because it’s a pointer; C only evaluates to false if something is 0nil
orfalse
The only surprising one here is Javascript. I argue Lua and Python make sense for the same reason, Lua just decided to evaluate truthiness based on whether the variable is set, whereas Python decided to evaluate it based on the contents of the variable. I prefer the Python approach here, but I prefer Lua as a language generally (love the simplicity).