emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (format "Hello %1$S%2$s" 'world "!")


From: Vivek Dasmohapatra
Subject: Re: (format "Hello %1$S%2$s" 'world "!")
Date: Sun, 2 Jul 2017 17:56:43 +0100 (BST)
User-agent: Alpine 2.02 (DEB 1266 2009-07-14)

Also, the syntax is very heavy. Was it inspired by another programming language? The ones I'm familiar with use $1, {1}, or similar syntax, but I've never seen %1$s :/

From printf(3):

  By default, the arguments are used in the order given, …
  One can also specify explicitly which argument is taken, at each place
  where an argument is required, by writing "%m$" instead of '%' and "*m$"
  instead of '*', where the decimal integer m denotes the position in the
  argument list of the desired argument, indexed starting from 1.  Thus,

       printf("%*d", width, num);
       and
       printf("%2$*1$d", width, num);

https://en.wikipedia.org/wiki/Printf_format_string#Parameter_field

I don't know when POSIX introduced it, but it's been around for a while.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]