Bram Moolenaar <b...@moolenaar.net> wrote: > 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.
This is known as the 'elvis operator', which exists in several languages. See: https://en.wikipedia.org/wiki/Elvis_operator Generally, it is ?: as in: var name = Getname() ?: 'unknown'; It may be worth saying that it is almost equivalent to the longer: var name = Getname() ? Getname() : 'unknown'; ... except that in the case of the elvis operator, Gename() is guaranteed to be invoked only once, which may not only be more efficient, but can also be different if Getname() had side effects. This image explains why it's called the 'elvis operator': https://i.stack.imgur.com/bVG64.png Regards Dominique -- -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/CAON-T_hAu7PD1%2Bx4LW8DZhTtrVf6j7FM%2BCKrKS1moqoTgHd29g%40mail.gmail.com.