Jinsong Zhao
5/9/2015 1:45:00 PM
On 2015/5/9 19:28, Jinsong Zhao wrote:
> On 2015/5/9 9:44, Pascal J. Bourguignon wrote:
>> Jinsong Zhao <jszhao@yeah.net> writes:
>>
>>> Hi there,
>>>
>>> I have the following format code.
>>>
>>> (format nil "~{No.=~A : I will do ~[this~;that~;both~].~}" (rest
>>> '(No. 1)))
>>>
>>> I hope it could output:
>>>
>>> No.=1 : I will do that.
>>>
>>> However, it breaks because of no more arguments.Is it possible to make
>>> it work by only changing the control-string?
>>
>> Yes. You can use ~* to move around in the argument list.
>>
>> ~:* means "previous argument":
>> (format nil "~{No.=~A : I will do ~:*~[this~;that~;both~].~}"
>> (rest '(No. 1)))
>> --> "No.=1 : I will do that."
>>
>> ~n@* means "argument number n":
>> (format nil "~{No.=~A : I will do ~0@*~[this~;that~;both~].~}"
>> (rest '(No. 1)))
>> --> "No.=1 : I will do that."
>>
>
The last question about control-string
In the following code
(format t "~%~{~1@*~:[N~;M~] - ~1@*~:[~0@*~A~; ~1@*~A and ~0@*~A~]~}" lst)
if lst is '(abc nil) the output is
N - ABC
if lst is '(abc def), the output is
M - DEF and ABC
However, the above code run into infinite iteration. I try to add ~^
inside ~{~}, however, it does not terminate the iteration.
I hope to get rid of nil in '(abc nil), however, in this case, I can't
get the correct result. Is it possible get the same result with '(abc)
by changing control-string?
I appreciate you for any suggestion and help.
Best,
Jinsong