Recursion in mappings

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Recursion in mappings

Bertram Scharpf
Hi,

I read vim tip #1198 and I'm amazed the recursion doesn't
lead to a stack overflow. I tried to force one and waited
for estimately 150M executions:

  map <silent><F6> :if strlen(getline("."))<78\|exec "norm Ax\e"\|else\|pu_\|endif\|redraw<cr><F6>

Can I rely on this and if yes, why?

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Reply | Threaded
Open this post in threaded view
|

Re: Recursion in mappings

iler.ml
On 4/10/06, Bertram Scharpf <[hidden email]> wrote:
> I read vim tip #1198 and I'm amazed the recursion doesn't
> lead to a stack overflow. I tried to force one and waited
> for estimately 150M executions:
>
>   map <silent><F6> :if strlen(getline("."))<78\|exec "norm Ax\e"\|else\|pu_\|endif\|redraw<cr><F6>
>
> Can I rely on this and if yes, why?

Bertram,

    :help recursive_mapping
and
    :help 'maxmapdepth'
explains some of it.

The  :help 'maxmapdepth' explains why 'maxmapdepth' does not apply
to "tail recursion" case.

I think that with "tail recursion" recursive mappings,
vim memory does not grow (confirmed by your experiment.)

I think C recursion or stack grows is *not* involved in processing of
recursive mappings, I think the code manipulates the input queue.
This is my guess though.

You can read more about general notion of "tail recursion" at
    http://en.wikipedia.org/wiki/Tail_call

Yakov