Consider this FORMAT expression:
(format nil "~d ~:p" 1) ==> "1 "
Now according to the Hyperspec, ·@? consumes one argument which
is processed as part of the control string as if it had appeared in
place of the ·@? construct, and any directives in the recursively
processed control string may consume arguments of the control string
containing the ·@? directive.
So I'd expect that I can replace ~:p with ·@? like this:
(format nil "~d ·@?" 1 "~:p")
However in Allegro 7.0 and the oldish version of CLISP I have lying
around on my mac, this results in "1 s" rather than "1 ". Is that
correct behavior? I was hoping that the recursive format control could
back up to preceeding arguments so one could deal with irregular
pluralizations:
(format nil "You see ~d ·@?" number noun)
where `noun' might be "tree~:p" or "el~:*~[ves~;f~:;ves~]".
-Peter
--
Peter Seibel
·····@javamonkey.com
http://www.gigamonkeys.com/book/
Peter Seibel wrote:
> Consider this FORMAT expression:
>
> (format nil "~d ~:p" 1) ==> "1 "
>
> Now according to the Hyperspec, ·@? consumes one argument which
>
> is processed as part of the control string as if it had appeared in
> place of the ·@? construct, and any directives in the recursively
> processed control string may consume arguments of the control string
> containing the ·@? directive.
>
> So I'd expect that I can replace ~:p with ·@? like this:
>
> (format nil "~d ·@?" 1 "~:p")
>
> However in Allegro 7.0 and the oldish version of CLISP I have lying
> around on my mac, this results in "1 s" rather than "1 ". Is that
> correct behavior?
LispWorks result:
CL-USER 17 > (format nil "~d ·@?" 1 "~:p")
Error: Number expected in ~p format, got NIL.
1 (abort) Return to level 0.
2 Return to top loop level 0.
clt
From: Thomas A. Russ
Subject: Re: Yet another FORMAT questionn, ·@? this time
Date:
Message-ID: <ymi1xdk5ra8.fsf@sevak.isi.edu>
Peter Seibel <·····@javamonkey.com> writes:
>
> Consider this FORMAT expression:
>
> (format nil "~d ~:p" 1) ==> "1 "
>
> Now according to the Hyperspec, ·@? consumes one argument which
>
> is processed as part of the control string as if it had appeared in
> place of the ·@? construct, and any directives in the recursively
> processed control string may consume arguments of the control string
> containing the ·@? directive.
>
> So I'd expect that I can replace ~:p with ·@? like this:
>
> (format nil "~d ·@?" 1 "~:p")
The problem is that the "~:p" is an argument as well. You would get the
behavior you desire with this format string:
(format nil "~d ·@?" 1 "~2:*~p~*")
which uses "~2:*" to back up two arguments and then "~*" to skip forward
one more. This is of course a bit uglier then what is shown below.
> However in Allegro 7.0 and the oldish version of CLISP I have lying
> around on my mac, this results in "1 s" rather than "1 ". Is that
> correct behavior? I was hoping that the recursive format control could
> back up to preceeding arguments so one could deal with irregular
> pluralizations:
>
> (format nil "You see ~d ·@?" number noun)
>
> where `noun' might be "tree~:p" or "el~:*~[ves~;f~:;ves~]".
"tree~2:*~p~*" "el~:2*~[ves~;f~:;ves~]~*"
Unfortunately, I don't see any way around this, although you could
encode the final skip forward in the original string (but that would
IMHO be worse from a modularity and interaction point of view). The
backward skip can't go into the base string or it wouldn't let you get
the format argument string in.
--
Thomas A. Russ, USC/Information Sciences Institute
From: Peter Seibel
Subject: Re: Yet another FORMAT questionn, ·@? this time
Date:
Message-ID: <m38y7smi7p.fsf@javamonkey.com>
···@sevak.isi.edu (Thomas A. Russ) writes:
> Peter Seibel <·····@javamonkey.com> writes:
>
>>
>> Consider this FORMAT expression:
>>
>> (format nil "~d ~:p" 1) ==> "1 "
>>
>> Now according to the Hyperspec, ·@? consumes one argument which
>>
>> is processed as part of the control string as if it had appeared in
>> place of the ·@? construct, and any directives in the recursively
>> processed control string may consume arguments of the control string
>> containing the ·@? directive.
>>
>> So I'd expect that I can replace ~:p with ·@? like this:
>>
>> (format nil "~d ·@?" 1 "~:p")
>
> The problem is that the "~:p" is an argument as well. You would get
> the behavior you desire with this format string:
>
>
> (format nil "~d ·@?" 1 "~2:*~p~*")
Ah, of course. Duh. Thanks.
> which uses "~2:*" to back up two arguments and then "~*" to skip forward
> one more. This is of course a bit uglier then what is shown below.
>
>> However in Allegro 7.0 and the oldish version of CLISP I have lying
>> around on my mac, this results in "1 s" rather than "1 ". Is that
>> correct behavior? I was hoping that the recursive format control could
>> back up to preceeding arguments so one could deal with irregular
>> pluralizations:
>>
>> (format nil "You see ~d ·@?" number noun)
>>
>> where `noun' might be "tree~:p" or "el~:*~[ves~;f~:;ves~]".
>
> "tree~2:*~p~*" "el~:2*~[ves~;f~:;ves~]~*"
I think I might use "~:*tree~:p~*" and "~:*el~:*~[ves~;f~:;ves~]~*",
i.e. just bracket the "real" control string to be embedded with
~:*/~*. But that's just another way of saying the same thing.
-Peter
--
Peter Seibel ·····@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp
"Peter Seibel" <·····@javamonkey.com> wrote in message ···················@javamonkey.com...
> ···@sevak.isi.edu (Thomas A. Russ) writes:
>
>> Peter Seibel <·····@javamonkey.com> writes:
>>
>>>
>>> Consider this FORMAT expression:
>>>
>>> (format nil "~d ~:p" 1) ==> "1 "
>>>
>>> Now according to the Hyperspec, ·@? consumes one argument which
>>>
>>> is processed as part of the control string as if it had appeared in
>>> place of the ·@? construct, and any directives in the recursively
>>> processed control string may consume arguments of the control string
>>> containing the ·@? directive.
>>>
>>> So I'd expect that I can replace ~:p with ·@? like this:
>>>
>>> (format nil "~d ·@?" 1 "~:p")
>>
>> The problem is that the "~:p" is an argument as well. You would get
>> the behavior you desire with this format string:
>>
>>
>> (format nil "~d ·@?" 1 "~2:*~p~*")
>
> Ah, of course. Duh. Thanks.
>
Doesn't appear to work in Lispworks, it gives a bounds error as if
it's recursing on what remains of the format string and arguments.
i.e. (format nil "~2:*~p~*")
Best I could come up with is
(format nil "You see ·@?" (concatenate 'string "~d " noun) number)
--
Geoff