From: Peter Seibel
Subject: Yet another FORMAT questionn, ·@? this time
Date: 
Message-ID: <m27jndufl9.fsf@peter-ibook.local>
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/

From: Carl Taylor
Subject: Re: Yet another FORMAT questionn, ·@? this time
Date: 
Message-ID: <tjExd.1129727$Gx4.969847@bgtnsc04-news.ops.worldnet.att.net>
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
From: Geoffrey Summerhayes
Subject: Re: Yet another FORMAT questionn, ·@? this time
Date: 
Message-ID: <7pNxd.11657$GK5.762967@news20.bellglobal.com>
"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 
From: Geoffrey Summerhayes
Subject: Re: Yet another FORMAT questionn, ·@? this time
Date: 
Message-ID: <A1Oxd.11803$GK5.778959@news20.bellglobal.com>
"Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> wrote in message ···························@news20.bellglobal.com...
>
>
> Best I could come up with is
>
> (format nil "You see ·@?" (concatenate 'string "~d " noun) number)
>

Even stranger:

Allegro
CG-USER(1): (format nil "~d ·@?" 1 ···@··@{~A~}" 2 3 4)
"1 ···@··@{~A~}234"

Clisp
[1]> (format nil "~d ·@?" 1 ···@··@{~A~}" 2 3 4)
"1 ···@··@{~A~}234"

LW
CL-USER 7 : 2 > (format nil "~d ·@?" 1 ···@··@{~A~}" 2 3 4)
"1 234"

Corman
(format nil "~d ·@?" 1 ···@··@{~A~}" 2 3 4)
;;; An error occurred in function APPLY:
;;; Error: Not a list: 2
;;; Entering Corman Lisp debug loop.
;;; Use :C followed by an option to exit. Type :HELP for help.
;;; Restart options:
;;; 1 Abort to top level.

Corman doesn't handle the @ modifier correctly.
(format nil "~d ·@?" 1 ···@··@{~A~}" '(2 3 4))
"1 234"

Most portable way under the lisps I've tried:

(let ((number 2)(noun "tree~:p"))
   (format nil "You see ~?"
           (concatenate 'string "~d " noun)
           (list number)))

--
Geoff