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 -- [email protected] -- 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 ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202010031544.093FiA401865731%40masaka.moolenaar.net.