Execute HQ9+/Common Lisp: Difference between revisions

m
Fixed syntax highlighting.
(category tags...)
m (Fixed syntax highlighting.)
 
(3 intermediate revisions by 3 users not shown)
Line 1:
{{implementation|HQ9+}}{{collection|RCHQ9+}}[[Category:Common Lisp]]
=={{header|Common Lisp}}==
{{implementation|HQ9+}}{{collection|RCHQ9+}}[[Category:Common Lisp]]
 
The interpreter (in [[Common Lisp]]) accepts a string, treated as program text, or a pathname object, in which case the contents of the file are the program text.
 
<langsyntaxhighlight lang="lisp">(defun slurp (filespec)
"Return the contents of the file as a string."
(with-output-to-string (out)
Line 19 ⟶ 18:
with accumulator = 0
for c across src
do (condcase c
((char-equal c #\h) (write-line "Hello, world!" out))
((char-equal c #\q) (write-linestring src out))
((char-equal c #\+) (incf accumulator))
((char-equal c #\9)
(do ((n 99 (1- n))) ((zerop n))
(format out "~&~%~w bottle~:p of beer on the wall~%~
Line 35 ⟶ 34:
Go to the store and buy some more~%~
99 bottles of beer on the wall.~%")))
finally (return accumulator)))</langsyntaxhighlight>
9,479

edits