Sunday, July 24, 2011

Re: why is call needed in vimscript?


cursor(4,0) is the _value_ of the function. For instance, in a Vim compiled with +float, acos(-1) is the arc-cosine (in radians) of minus one, i.e., the number pi. All functions return a value (if you execute a :return statement without an explicit return value, the function returns the integer zero).

You can use that value in an expression: e.g.

       if cursor(4,0)
               echoerr 'Couldn't set cursor to (4,0)'
       endif

With :call, you call the function and throw away the return value — meaning that in that case you're only interested in the "side effects" (moving the cursor, in this example) and not in the result (for an arithmetic function, the result of the calculation; the result of the cursor() function can be 0 for success or -1 for failure).

":help :call" says it quite clearly IMO: see the first and last sentences of its first paragraph, quoted below:

               Call a function.  The name of the function and its arguments
               are as specified with |:function|.  Up to 20 arguments can be
               used.  The returned value is discarded.



Hi,

I understand it better now. Thanks for the comments.
By the way, I think I was searching the wrong thing. ":help :call" is clear, you are right, but what I tried was ":help call" and I got a little bit puzzled. My fault.

Thanks all of you for your comments.

Cheers,
Jose





 

--
You received this message from the "vim_use" 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

No comments: