Thursday, February 14, 2013

Passing optional arguments from function to function.

Hello all,

I want to write a function which, to put it simply, would look like
this (which of course doesn't work):

function! Echo (...)
echo printf(...)
endfunction

i.e. "Echo" takes optional arguments and passes them to "printf". The
best I've come so far is:

function! Echo (...)
let s = "printf(a:1"
let i = 2
while i <= a:0
let s = s . ", a:" . i
let i = i + 1
endwhile
let s = s . ")"
execute "echo " . s
endfunction

It works, but it's terribly inelegant. So, am I missing something?

Best,
Paul

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: