Can anyone tell me the exact behavior of the format directive "~#[" ?
I only found one mention of it in the HyperSpec, on the very bottom of:
http://www.xanalys.com/software_tools/reference/HyperSpec/Body/22_cgb.htm
and I can't quite figure it out from that.
Thanks,
Tim
--
Turing Stable: (adj) The property of continuing to be Turing complete,
after running for an hour.
"Tim Daly, Jr." <···@ponder.intern> wrote in message ···················@ponder.intern...
>
> Can anyone tell me the exact behavior of the format directive "~#[" ?
>
> I only found one mention of it in the HyperSpec, on the very bottom of:
>
> http://www.xanalys.com/software_tools/reference/HyperSpec/Body/22_cgb.htm
>
> and I can't quite figure it out from that.
Normally, the ~[ ...] directive would take a number from the
format argument list, however you can use a numeric parameter.
~3[a~;b~;c~;d~;e~] would just print the d.
The # modifier can be used instead of a number, and it represents
the number of remaning arguments. So ~#[ ...] would dispatch on
the number of remaining arguments.
"Joe Marshall" <·············@attbi.com> writes:
> Normally, the ~[ ...] directive would take a number from the
> format argument list, however you can use a numeric parameter.
> ~3[a~;b~;c~;d~;e~] would just print the d.
>
> The # modifier can be used instead of a number, and it represents
> the number of remaning arguments. So ~#[ ...] would dispatch on
> the number of remaining arguments.
>
Ah! Thank you very much. :)
-Tim
--
Turing Stable: (adj) The property of continuing to be Turing complete,
after running for an hour.
Tim Daly, Jr. wrote:
>
> Can anyone tell me the exact behavior of the format directive "~#[" ?
> I only found one mention of it in the HyperSpec, on the very bottom of:
> http://www.xanalys.com/software_tools/reference/HyperSpec/Body/22_cgb.htm
> and I can't quite figure it out from that.
Here are the pieces of the puzzle.
0. [22.3.7.2] "The argth clause is selected, where the first clause
is number 0."
So (format nil "~[a~;b~;c~]" 1) ==> "b".
1. [22.3.7.2] "If a prefix parameter is given (as ~n[), then
the parameter is used instead of an argument."
So (format nil "~1[a~;b~;c~]") ==> "b".
2. [22.3] "# can be used in place of a prefix parameter; it
represents the number of args remaining to be processed."
So (format nil "~#[a~;b~;c~]" 999) ==> "b".
With that in view, the cryptic example at the end of 22.3.7.2
may now be helpful. :-) Note, however, that it is incorrect
(at least in the version of the HyperSpec I have): there should
be no space between >>>~^<<< and >>>,~}<<<.
--
Gareth McCaughan ················@pobox.com
.sig under construc
················@pobox.com (Gareth McCaughan) writes:
[snip]
> 2. [22.3] "# can be used in place of a prefix parameter; it
> represents the number of args remaining to be processed."
>
> So (format nil "~#[a~;b~;c~]" 999) ==> "b".
Ah ha! This was the key piece. :) Thank you.
-Tim
--
Turing Stable: (adj) The property of continuing to be Turing complete,
after running for an hour.