On 18/06/10 18:38, Bee wrote:
Can I rely on left to right evaluation?
Is there a problem with this phrase and the order of evaluation?
@b + setreg('b', @l<n ? @b : @b+1 )
Is it a "tricky side effect semantics" as John Little warns?
Note: setreg() Returns zero for success
Well, if setreg() returns zero for success, then that zero will be
returned after setting @b to @b+1. However, I expect that the old value
of @b may have been pushed onto the stack before that, so that the
expression will return the former value of @b. (Vimscript is an
interpreted language, not a compiled one; therefore I don't expect
"arithmetic optimization" to come into play.) But I might be wrong.
In this case I don't expect failure to be a possible outcome, so a
simpler (and also more predictable) command would be either
:let b = @b += (@l >= n) | let whatever = b
or
:let whatever = @b | let @b += (@l >= n)
depending on what you mean. Note that registers normally have a String
value. The above evaluates at least one register as a Number (two if
variable n holds a Number), which means that if the register is either
empty or does not start with a digit, it evaluates to zero. For instance
('bcd' + 1) evaluates to 1 and ('12qx' >= 5) evaluates to TRUE i.e. 1
(because 12 >= 5).
Best regards,
Tony.
--
Money is the root of all wealth.
--
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