From: Tim Daly, Jr.
Subject: format directive ~#[
Date: 
Message-ID: <m3vg7fzetw.fsf@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.


Thanks, 
Tim

-- 
Turing Stable: (adj) The property of continuing to be Turing complete,
after running for an hour.

From: Joe Marshall
Subject: Re: format directive ~#[
Date: 
Message-ID: <gy_Y8.60926$uw.33240@rwcrnsc51.ops.asp.att.net>
"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.
From: Tim Daly, Jr.
Subject: Re: format directive ~#[
Date: 
Message-ID: <m3ptxnz9mr.fsf@ponder.intern>
"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.
From: Gareth McCaughan
Subject: Re: format directive ~#[
Date: 
Message-ID: <slrnaj8rpu.k5h.Gareth.McCaughan@g.local>
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
From: Tim Daly, Jr.
Subject: Re: format directive ~#[
Date: 
Message-ID: <m3lm8bz9kg.fsf@ponder.intern>
················@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.