[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

please help on format control-string

Jinsong Zhao

5/9/2015 1:41:00 AM

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?

Thanks a lot.

Best,
Jinsong
6 Answers

Pascal J. Bourguignon

5/9/2015 1:45:00 AM

0

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."

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Jinsong Zhao

5/9/2015 2:08:00 AM

0

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."
>

Thank you very much!

Best,
Jinsong

William James

5/9/2015 6:11:00 AM

0

Pascal J. Bourguignon wrote:

> > (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."

Gauche Scheme:

(let1 n (last '(No. 1)) #"No.=~n : I will do ~(~'(this that both) n).")
===>
"No.=1 : I will do that."

--
This is war and our greatest enemy is the enemy within: the submissive,
apologetic, guilt-ridden, self-hating drone. The moment we manage to destroy
the enemy within, destroying the rest of our enemies will be a walk in the
park. --- http://www.kolumbus.fi/aquilon/londonsp...

Jinsong Zhao

5/9/2015 11:29:00 AM

0

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."
>

Another similar question:

If the argument is (rest '(No. 10)) instead of (rest '(No. 1)). how to
get the output:

No.=10 : I will do that.

(format nil "~{No.=~A : I will do ~0@*~[this~;that~;both~].~}" (rest
'(No. 10)))

is it possible to do some manipulation on arguments in control-string?

Thanks again!

Best,
Jinsong

Jinsong Zhao

5/9/2015 1:45:00 PM

0

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

Pascal J. Bourguignon

5/9/2015 10:01:00 PM

0

Jinsong Zhao <jszhao@yeah.net> writes:

> 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.

This is normal, since you used ~@* which is the absolute addressing of
arguments.

Use ~* and ~:* instead, or go back to the end of the list with ~@ before
~^~}.


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk