99 Bottles of Beer/Lisp: Difference between revisions
Content added Content deleted
(moving code from main task-page to sub-page) |
(moving code from main task-page to sub-page) |
||
Line 9: | Line 9: | ||
See [[99 Bottles of Beer/Lisp]] |
See [[99 Bottles of Beer/Lisp]] |
||
--> |
--> |
||
=={{header|ACL2}}== |
|||
<lang Lisp>(defun bottles-of-beer (n) |
|||
(if (zp n) |
|||
nil |
|||
(prog2$ (cw (concatenate 'string |
|||
"~%" |
|||
"~N0 bottle~#1~[~/s~] of beer on the wall,~%" |
|||
"~n0 bottle~#1~[~/s~] of beer.~%" |
|||
"Take one down, pass it around,~%" |
|||
"~n2 bottle~#3~[~/s~] of beer on the wall.~%") |
|||
n |
|||
(if (= n 1) 0 1) |
|||
(1- n) |
|||
(if (= n 2) 0 1)) |
|||
(bottles-of-beer (- n 1)))))</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 24: | Line 40: | ||
<lang lisp>(format t "~{~[~^~]~:*~D bottle~:P of beer on the wall~%~:*~D bottle~:P of beer~%Take one down, pass it around~%~D bottle~:P~:* of beer on the wall~2%~}" |
<lang lisp>(format t "~{~[~^~]~:*~D bottle~:P of beer on the wall~%~:*~D bottle~:P of beer~%Take one down, pass it around~%~D bottle~:P~:* of beer on the wall~2%~}" |
||
(loop :for n :from 99 :downto 0 :collect n))</lang> |
(loop :for n :from 99 :downto 0 :collect n))</lang> |
||
The [http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm FORMAT function] is probably the most baroque (i.e. featureful almost to a fault) function in Common Lisp. |
The [http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm FORMAT function] is probably the most baroque (i.e. featureful almost to a fault) function in Common Lisp. |
||
To really drive this point home, try replacing each instance of <tt>~D</tt> |
|||
with <tt>~R</tt>, and then with <tt>~@R</tt>. |
|||
Yes, this is all standard and dependable (dys?)functionality. |
|||
Explanation of the format string for the uninitiated: |
Explanation of the format string for the uninitiated: |