You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the continuation of the work on issue #609. To evaluate the compatibility of Medley Common Lisp with ANSI Common Lisp I'm testing on Medley the code of Peter Seibel's book Practical Common Lisp.
Session transcript
I evaluated the expressions of chapter 18 at a XCL Exec. A couple of function calls have references to reserved symbols such as list and char, so I replaced them with literal values.
This code gives a pretty good shakeup to format and yet it seems to work as expected:
2/8> (loop for cons on '(12345)
do (formatt"~a" (carcons))
when (cdrcons) do (formatt", "))
1, 2, 3, 4, 5NIL
2/9>
2/9> (formatt"~{~a~^, ~}"'(12345))
1, 2, 3, 4, 5NIL
2/10>
2/10> (formatt"~$"pi)
3.14NIL
2/11>
2/11> (formatt"~5$"pi)
3.14159NIL
2/12>
2/12> (formatt"~v$"3pi)
3.142NIL
2/13>
2/13> (formatt"~#$"pi)
3.1NIL
2/14>
2/14> (formatt"~,5f"pi)
3.14159NIL
2/15>
2/15> (formatt"~d"1000000)
1000000NIL
2/16>
2/16> (formatt"~:d"1000000)
1,000,000NIL
2/17>
2/17> (formatt"~@d"1000000)
+1000000NIL
2/18>
2/18> (formatt"~:@d"1000000)
+1,000,000NIL
2/19>
2/19> (formatnil"The value is: ~a"10)
"The value is: 10"
2/20>
2/20> (formatnil"The value is: ~a""foo")
"The value is: foo"
2/21>
2/21> (formatnil"The value is: ~a" (list123))
"The value is: (1 2 3)"
2/22>
2/22> (formatt"Syntax error. Unexpected character: ~:c"#\a)
Syntax error. Unexpected character: a
NIL
2/23>
2/23> (formatt"~@c~%"#\a)
#\aNIL
2/24>
2/24> (formatnil"~:@c" (code-char0))
"Null"
2/25>
2/25> (formatnil"~d"1000000)
"1000000"
2/26>
2/26> (formatnil"~:d"1000000)
"1,000,000"
2/27>
2/27> (formatnil"~@d"1000000)
"+1000000"
2/28>
2/28> (formatnil"~:@d"1000000)
"+1,000,000"
2/29>
2/29> (formatnil"~12d"1000000)
" 1000000"
2/30>
2/30> (formatnil"~12,'0d"1000000)
"000001000000"
2/31>
2/31> (formatnil"~4,'0d-~2,'0d-~2,'0d"2005610)
"2005-06-10"
2/32>
2/32> (formatnil"~:d"100000000)
"100,000,000"
2/33>
2/33> (formatnil"~,,'.,4:d"100000000)
"1.0000.0000"
2/34>
2/34> (formatnil"~x"1000000)
"F4240"
2/35>
2/35> (formatnil"~o"1000000)
"3641100"
2/36>
2/36> (formatnil"~b"1000000)
"11110100001001000000"
2/37>
2/37> (formatnil"~f"pi)
"3.1415927"
2/38>
2/38> (formatnil"~,4f"pi)
"3.1416"
2/39>
2/39> (formatnil"~e"pi)
"3.1415927"
2/40>
2/40> (formatnil"~,4e"pi)
"3.1416E+0"
2/41>
2/41> (formatnil"~$"pi)
"3.14"
2/42>
2/42> (formatnil"~2,4$"pi)
"0003.14"
2/43>
2/43> (formatnil"~r"1234)
"one thousand two hundred thirty-four"
2/44>
2/44> (formatnil"~:r"1234)
"one thousand two hundred thirty-fourth"
2/45>
2/45> (formatnil"~@r"1234)
"MCCXXXIV"
2/46>
2/46> (formatnil"~:@r"1234)
"MCCXXXIIII"
2/47>
2/47> (formatnil"file~p"1)
"file"
2/48>
2/48> (formatnil"file~p"10)
"files"
2/49>
2/49> (formatnil"file~p"0)
"files"
2/50>
2/50> (formatnil"~r file~:p"1)
"one file"
2/51>
2/51> (formatnil"~r file~:p"10)
"ten files"
2/52>
2/52> (formatnil"~r file~:p"0)
"zero files"
2/53>
2/53> (formatnil"~r famil~:@p"1)
"one family"
2/54>
2/54> (formatnil"~r famil~:@p"10)
"ten families"
2/55>
2/55> (formatnil"~r famil~:@p"0)
"zero families"
2/56>
2/56> (formatnil"~(~a~)""FOO")
"foo"
2/57>
2/57> (formatnil"~(~@r~)"124)
"cxxiv"
2/58>
2/58> (formatnil"~(~a~)""tHe Quick BROWN foX")
"the quick brown fox"
2/59>
2/59> (formatnil"~@(~a~)""tHe Quick BROWN foX")
"The quick brown fox"
2/60>
2/60> (formatnil"~:(~a~)""tHe Quick BROWN foX")
"The Quick Brown Fox"
2/61>
2/61> (formatnil"~:@(~a~)""tHe Quick BROWN foX")
"THE QUICK BROWN FOX"
2/62>
2/62> (formatnil"~[cero~;uno~;dos~]"0)
"cero"
2/63>
2/63> (formatnil"~[cero~;uno~;dos~]"1)
"uno"
2/64>
2/64> (formatnil"~[cero~;uno~;dos~]"2)
"dos"
2/65>
2/65> (formatnil"~[cero~;uno~;dos~]"3)
""
2/66>
2/66> (formatnil"~[cero~;uno~;dos~:;mucho~]"3)
"mucho"
2/67>
2/67> (formatnil"~[cero~;uno~;dos~:;mucho~]"100)
"mucho"
2/68>
2/68> (defparameter*list-etc*"~#[NONE~;~a~;~a and ~a~:;~a, ~a~]~#[~; and ~a~:;, ~a, etc~].")
*LIST-ETC*
2/69>
2/69> (formatnil*list-etc*)
"NONE."
2/70>
2/70> (formatnil*list-etc*'a)
"A."
2/71>
2/71> (formatnil*list-etc*'a 'b)
"A and B."
2/72>
2/72> (formatnil*list-etc*'a 'b 'c)
"A, B and C."
2/73>
2/73> (formatnil*list-etc*'a 'b 'c 'd)
"A, B, C, etc."
2/74>
2/74> (formatnil*list-etc*'a 'b 'c 'd 'e)
"A, B, C, etc."
2/75>
2/75> (defvar test-result t)
TEST-RESULT
2/76>
2/76> (formatt"~:[FAIL~;pass~]" test-result)
pass
NIL
2/77>
2/77> (formatnil"~@[x = ~a~]~@[y = ~a~]"1020)
"x = 10 y = 20"
2/78>
2/78> (formatnil"~@[x = ~a~]~@[y = ~a~]"10nil)
"x = 10 "
2/79>
2/79> (formatnil"~@[x = ~a~]~@[y = ~a~]"nil20)
"y = 20"
2/80>
2/80> (formatnil"~@[x = ~a~]~@[y = ~a~]"nilnil)
""
2/81>
2/81> (formatnil"~{~a, ~}" (list123))
"1, 2, 3, "
2/82>
2/82> (formatnil"~{~a~^, ~}" (list123))
"1, 2, 3"
2/83>
2/83> (formatnil"~@{~a~^, ~}"123)
"1, 2, 3"
2/84>
2/84> (formatnil"~{~a~#[~;, and ~:;, ~]~}" (list123))
"1, 2, and 3"
2/85>
2/85> (formatnil"~{~a~#[~;, and ~:;, ~]~}" (list12))
"1, and 2"
2/86>
2/86> (defparameter*english-list*"~{~#[~;~a~;~a and ~a~:;~@{~a~#[~;, and ~:;, ~]~}~]~}")
*ENGLISH-LIST*
2/87>
2/87> (formatnil*english-list*'())
""
2/88>
2/88> (formatnil*english-list*'(1))
"1"
2/89>
2/89> (formatnil*english-list*'(12))
"1 and 2"
2/90>
2/90> (formatnil*english-list*'(123))
"1, 2, and 3"
2/91>
2/91> (formatnil*english-list*'(1234))
"1, 2, 3, and 4"
2/92>
2/92> (defparameter*english-list*"~{~#[<empty>~;~a~;~a and ~a~:;~@{~a~#[~;, and ~:;, ~]~}~]~:}")
New VARIABLES definition for *ENGLISH-LIST*.
*ENGLISH-LIST*
2/93>
2/93> (formatnil*english-list*'())
"<empty>"
2/94>
2/94> (formatnil"~r~:*(~d)"1)
"one (1)"
2/95>
2/95> (formatnil"I saw ~r el~:*~[ves~;f~:;ves~]."0)
"I saw zero elves."
2/96>
2/96> (formatnil"I saw ~r el~:*~[ves~;f~:;ves~]."1)
"I saw one elf."
2/97>
2/97> (formatnil"I saw ~r el~:*~[ves~;f~:;ves~]."2)
"I saw two elves."
2/98>
2/98> (formatnil"~{~s~*~^~}"'(:a10:b20))
":A :B"
2/99>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Chapter 18. A Few FORMAT Recipes
This is the continuation of the work on issue #609. To evaluate the compatibility of Medley Common Lisp with ANSI Common Lisp I'm testing on Medley the code of Peter Seibel's book Practical Common Lisp.
Session transcript
I evaluated the expressions of chapter 18 at a XCL Exec. A couple of function calls have references to reserved symbols such as
list
andchar
, so I replaced them with literal values.This code gives a pretty good shakeup to
format
and yet it seems to work as expected:Beta Was this translation helpful? Give feedback.
All reactions