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
> Thanks to a suggestion in vim_use I have "grouped" line numbering working.
>
> It is not a normal sequential numbering, but in groups of n lines.
>
> Example n=2
> ( 1_0_)
> ( 1_1_)
> ( 1_2_)
> ( 2_0_)
> ( 2_1_)
> ( 2_2_)
> ( 3_0_)
> ( 3_1_)
> ( 3_2_)
>
> vmap <F5> :<C-U>let n=15 <BAR> let @b=1 <BAR> let @l=0 <BAR>
> \ '<,'>s/^/\=printf("( %4d_%X_)",
> \ @b + setreg('b', @l<n ? @b : @b+1 ),
> \ @l + setreg('l', @l<n ? @l+1 : 0 ))<cr>
> endif
>
> > On Jun 16, 10:06 pm, John Little <[email protected]> wrote:
> > Please explain what you mean by the "tricky side effect semantics" as
> > I am learning.
>
> (Aren't we all?) In the expression
> @l + setreg('l', @l<str2nr(@n) ? @l+1 : 0 )
> the setting of the l register is a "side effect" of the evaluation of
> the expression, but the value of the expression could depend on this
> side effect. If the expression is evaluated strictly left to right,
> the value of @l is taken and then changed, but if the setreg was done
> first the answer would be different. The vim help says "All
> expressions within one level are parsed from left to right" but I
> could find no guarantee that it evaluates strictly left to right.
> Many languages, not least C and C++, explicitly prohibit such
> dependencies on the order of evaluation, though historically many
> compilers ignored them.
-Bill
--
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