EX3.13 format
formatを使って、単語のリストを取り文として表示する。
その際、
- formatは1度だけ呼び出す
- 先頭の単語の、先頭の文字は大文字に、それ以外は小文字にする。
- 最後の単語の後ろにはピリオドを打つ
を行う。
リファレンスを見たけど複雑過ぎてわからない。
~@( ~)で2番目の要求を満たせるけど、~{ ~}、~[ ~]との組み合わせをどうすればよく分からない。もう少し調べるか。
;;; Exercise 3.12 [m] Write a single expression using format that will ;;; take a list of words and print them as a sentence, with the first ;;; word capitalized and a period after the last word. You will have ;;; to consult a reference to learn new format directives.
色々苦労した跡↓
CL-USER> (format nil "~@(~a~)" 'hoge) "Hoge" CL-USER> (format nil "~@(~a~)" '(my name is mike)) "(My name is mike)" CL-USER> (format nil "~{~@(~a~)~}" '(my name is mike)) "MyNameIsMike" CL-USER> (format nil "~{~@(~a~) ~}" '(my name is mike)) "My Name Is Mike " CL-USER> (format nil "~@(~{~s~^ ~}~)." '(my name is mike)) "My name is mike."