Previous: , Up: Controlled Formatting   [Contents][Index]


6.4.4.3 Jump Directive

~*

The ‘~*’ directive, allows you to jump around in the list of format arguments. In its basic form, without modifiers, it simply skips the next argument, consuming it without emitting anything.

~:*

More often, however, it’s used with a colon modifier, which causes it to move backward, allowing the same argument to be used a second time. You can use ‘~:*’ to print a numeric argument once as a word and once in numerals like this:

(format nil "~r ~:*(~d)" 1) ==> "one (1)"

Or you could implement a directive similar to ‘~:P’ for an irregular plural by combing ‘~:*’ with ‘~[’.

(format nil "I saw ~r el~:*~[ves~;f~:;ves~]." 0) ==> "I saw zero elves."
(format nil "I saw ~r el~:*~[ves~;f~:;ves~]." 1) ==> "I saw one elf."
(format nil "I saw ~r el~:*~[ves~;f~:;ves~]." 2) ==> "I saw two elves."
~{...~*...

Within an ‘~{’ directive, ‘~*’ skips or backs up over the items in the list. For instance, you could print only the keys of a plist like this:

(format nil "~{~s~*~^ ~}" '(:a 10 :b 20)) ==> ":A :B"
~<p>*

The ‘~*’ directive can also be given a prefix parameter.

With no modifiers or with the colon modifier, this parameter specifies the number of arguments to move forward or backward and defaults to one

~<p>@*

With an at-sign modifier, the prefix parameter specifies an absolute, zero-based index of the argument to jump to, defaulting to zero. The at-sign variant of ‘~*’ can be useful if you want to use different control strings to generate different messages for the same arguments and if different messages need to use the arguments in different orders.


Previous: Iteration Directive, Up: Controlled Formatting   [Contents][Index]