Ozaki Kiichi wrote:

> > > I propose new conversion specifier '%v' (and '%V') of printf();
> > > inspired by golang.
> > > 
> > > This spec takes a value of any type and converts into string by 
> > > echo_string().
> > > 
> > > example:
> > > 
> > > " list
> > > :echo printf('%v', [0, 1, 2, 3])
> > > [0, 1, 2, 3]
> > > 
> > > " dict
> > > :echo printf('%v', {'str' : 'abcdef', 'num' : 123, 'pt' : 
> > > function('printf', ['%%'])})
> > > {'str': 'abcdef', 'num': 123, 'pt': function('printf', ['%%'])}
> > > 
> > > " funcref
> > > :echo printf('%v', function('str2nr'))
> > > str2nr
> > > 
> > > 
> > > '%V' is simular with '%S'.
> > > 
> > > patch:
> > > 
> > > https://gist.github.com/ichizok/c1ad7759d7a0a0734fb02f5a4d37445c
> > 
> > 
> > So, the same would be done with using "%s" and string() on the value?
> > 
> >    :echo printf('%s', string([0, 1, 2, 3]))
> >    [0, 1, 2, 3]
> > 
> > I suppose golang doesn't have a string() function.
> > 
> > An even simpler way is to do what Swift does:
> > 
> >     "lead \(expression) tail"
> > 
> > With the example above:
> >         "\([0, 1, 2, 3])"
> > 
> > I'm using this in Zimbu, works quite well.
> 
> When converting multiple values of any types (e.g. in debugging),
> it is rather bothersome to use string() to each values:
> 
> :echo printf('foo: %s, bar: %s, baz: %s, qux: %s', string(foo), string(bar), 
> string(baz), string(qux))
> 
> and, when a argument is string, string() is redundant.
> 
> Thus, simply:
> 
> :echo printf('foo: %v, bar: %v, baz: %v, qux: %v', foo, bar, baz, qux)
> 
> It is easy to reuse format string.
> 
> let fmt = '[%v] [%v] [%v]'
> ...
> echo printf(fmt, x1, x2, x3)
> ...
> echo printf(fmt, y1, y2, y3)

Well, since currently this produces an error, we could just convert to a
string when using "%s".

-- 
-rwxr-xr-x  1 root          24 Oct 29  1929 /bin/ed
-rwxr-xr-t  4 root      131720 Jan  1  1970 /usr/ucb/vi
-rwxr-xr-x  1 root  5.89824e37 Oct 22  1990 /usr/bin/emacs

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui