Hi,

At Thu, 19 Dec 2002 20:25:01 +0900,
Alexander Bokovoy wrote:
> It seems that there is a bug in recent sprintf changes which presents at least in 
> a snapshot of Ruby 1.7.3 dated 2002-11-17:
> 
> $ irb
> irb(main):001:0> sprintf("%*s", 10, "hello")
> "     hello"
> irb(main):002:0> sprintf("%*1$s", 10, "hello")
> ArgumentError: unnumbered(1) mixed with numbered
> 	from (irb):2:in `sprintf'
>         from (irb):2
> irb(main):003:0> sprintf("%*2$s", "hello", 10)
> ArgumentError: unnumbered(1) mixed with numbered
>         from (irb):3:in `sprintf'
>         from (irb):3

sprintf("%*1$2$s", 10, "hello")	# => "     hello"
sprintf("%2$*1$s", 10, "hello") # => "     hello"

This feature (numbered argument) is come from SUSv2:
http://www.opengroup.org/onlinepubs/007908799/xsh/fprintf.html
    The format can contain either numbered argument
    specifications (that is, %n$ and *m$), or unnumbered
    argument specifications (that is, % and *), but normally
    not both. The only exception to this is that %% can be
    mixed with the %n$ form.
    The results of mixing numbered and unnumbered argument
    specifications in a format string are undefined.

Incidentally, glibc doesn't allow such usage according to man
page of Linux.

    If the style using `$' is used, it must be used throughout
    for all conversions taking an argument and all width and
    precision arguments,

-- 
Nobu Nakada