On Jun 18, 12:41 pm, Tony Mechelynck <[email protected]>
wrote:
> 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.

I think "arithmetic optimization" might be what John meant by "tricky
side effect semantics".

Using an old Mac PowerBook Pismo 500MHz and a file of about 20k lines.
vim numbers all 20k lines in about 3 seconds using this:

let lpb=15 "lines per block (zero based)

vmap <F5> :<C-U> let @b=1 <BAR> let @l=0 <BAR>
  \ '<,'>s/^/\=printf("( %4d_%X_)",
  \ @b + setreg('b', @l<lpb ? @b : @b+1 ),
  \ @l + setreg('l', @l<lpb ? @l+1 : 0 ))<cr>

John gave me a version written as a function,
and it is just as fast and simpler to understand.

let lpb = 15 "lines per block (zero based)
function! Renum()
  let g:b = 1
  let g:l = 0
  '<,'>s/^/\=ResInc()/
endfunction
function! ResInc()
  let result = printf('( %4d_%X_)', g:b, g:l)
  if g:l < g:lpb
    let g:l += 1
  else
    let g:l = 0
    let g:b += 1
  endif
  return result
endfunction
vmap <F4> :<c-u>call Renum()<cr>

-- 
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

Raspunde prin e-mail lui