As a first approach I have used what TypeScript does. However,
considering the feedback I have received, it's not very consistent and
has a few surprising sides.
One thing is that the "||" and "&&" operators do not result in a boolean
true or false, but the argument value. This is nice for something like:
var name = Getname() || 'unknown'
When the result of Getname() is falsy (null or empty) then the result
is "unknown".
However, when the result should be a boolean, this does not work:
var flag: bool = Getname() || false
On top of that, the order matters, this works:
var flag: bool = Getname() && true
But this doesn't:
var flag: bool = true && Getname()
That is unexpected if you consider && to be a boolean expression.
Therefore, I'm going to make && and || have a boolean result again.
I think that is the easiest to understand, and what most languages do.
For the first example, we can use a new operator which is specifically
for testing an expression to be falsy and using a replacement:
var name = Getname() ?? 'unknown'
Let me know if you have comments.
--
One difference between a man and a machine is that a machine is quiet
when well oiled.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///