fork download
  1. ;;; The format string in Common Lisp is almost a
  2. ;;; language on its own. Here's a Lisp version
  3. ;;; that shows its power. Hope you find it
  4. ;;; entertaining.
  5.  
  6. (in-package "CL-USER")
  7.  
  8. (defun bottle-song (&optional (in-stock 99) (stream *standard-output*))
  9.  
  10. ;; Original idea and primary coding by Geoff Summerhayes
  11. ;; <sumrnot@hotmail.com>
  12. ;; Formatting idea by Fred Gilham <gilham@snapdragon.csl.sri.com>
  13. ;; Actual formatting & minor recoding by Kent M Pitman
  14. ;; <pitman@world.std.com>
  15.  
  16. (format
  17.  
  18. stream
  19. "-----~2%~
  20. ~{~&~1&~
  21. ~[~^~:;~
  22. ~1:*~@(~
  23. ~R~) bo~
  24. ttle~:P o~
  25. f beer on t~
  26. he wall~01:*~[.~
  27. ~:;,~%~1:*~@(~R~
  28. ~) bottle~:*~P ~
  29. of beer.~%You t~
  30. ake one down, p~
  31. ass it around, ~
  32. ~01%~[*No* more~
  33. ~:;~:01*~@(~R~)~
  34. ~] bottle~:*~P ~
  35. of beer on the ~
  36. wall.~2&-----~%~
  37. ~1%~:*~]~]~}~0%"
  38.  
  39. (loop for bottle from in-stock downto 0 collect bottle)))
  40.  
  41.  
  42. (bottle-song)
Compilation error #stdin compilation error #stdout 5s 203840KB
stdin
Standard input is empty
compilation info
; compiling file "/home/N6mIUx/prog.lisp" (written 02 MAR 2019 10:29:22 AM):
; compiling (IN-PACKAGE "CL-USER")
; compiling (DEFUN BOTTLE-SONG ...)
; file: /home/N6mIUx/prog.lisp
; in: DEFUN BOTTLE-SONG
;     (FORMAT STREAM "-----~2%~
;             ~{~&~1&~
;             ~[~^~:;~
;             ~1:*~@(~
;             ~R~) bo~
;            ttle~:P o~
;           f beer on t~
;         he wall~01:*~[.~
;         ~:;,~%~1:*~@(~R~
;         ~) bottle~:*~P ~
;         of beer.~%You t~
;         ake one down, p~
;         ass it around, ~
;         ~01%~[*No* more~
;         ~:;~:01*~@(~R~)~
;         ~] bottle~:*~P ~
;         of beer on the ~
;         wall.~2&-----~%~
;         ~1%~:*~]~]~}~0%"
;             (LOOP FOR BOTTLE FROM IN-STOCK DOWNTO 0
;                   COLLECT BOTTLE))
; 
; caught WARNING:
;   error in FORMAT: Parameters found after #\: or #\@ modifier
;     -----~2%~
;             ~{~&~1&~
;             ~[~^~:;~
;             ~1:*~@(~
;             ~R~) bo~
;            ttle~:P o~
;           f beer on t~
;         he wall~01:*~[.~
;         ~:;,~%~1:*~@(~R~
;         ~) bottle~:*~P ~
;         of beer.~%You t~
;         ake one down, p~
;         ass it around, ~
;         ~01%~[*No* more~
;         ~:;~:01*~@(~R~)~
;         ~] bottle~:*~P ~
;         of beer on the ~
;         wall.~2&-----~%~
;         ~1%~:*~]~]~}~0%
;                                                                                                                                                                                                                                                                                                                ^
;   See also:
;     The ANSI Standard, Section 22.3
; 
; caught ERROR:
;   during macroexpansion of
;   (FORMATTER "-----~2%~
;             ~{~&~1&~
;             ~[~^~:;~
;             ~1:*~@(~
;             ~R~) bo~
;            ttle~:P o~
;           f beer on t~
;         he wall~01:*~[.~
;         ~:;,~%~1:*~@(~R~
;         ~) bottle~:*~P ~
;         of beer.~%You t~
;         ake one down, p~
;         ass it around, ~
;         ~01%~[*No* more~
;         ~:;~:01*~@(~R~)~
;         ~] bottle~:*~P ~
;         of beer on the ~
;         wall.~2&-----~%~
;         ~1%~:*~]~]~}~0%").
;   Use *BREAK-ON-SIGNALS* to intercept.
;   
;    error in FORMAT: Parameters found after #\: or #\@ modifier
;     -----~2%~
;             ~{~&~1&~
;             ~[~^~:;~
;             ~1:*~@(~
;             ~R~) bo~
;            ttle~:P o~
;           f beer on t~
;         he wall~01:*~[.~
;         ~:;,~%~1:*~@(~R~
;         ~) bottle~:*~P ~
;         of beer.~%You t~
;         ake one down, p~
;         ass it around, ~
;         ~01%~[*No* more~
;         ~:;~:01*~@(~R~)~
;         ~] bottle~:*~P ~
;         of beer on the ~
;         wall.~2&-----~%~
;         ~1%~:*~]~]~}~0%
;                                                                                                                                                                                                                                                                                                                ^
;   See also:
;     The ANSI Standard, Section 22.3

; ==>
;   (FORMAT SB-C::DEST
;           (FORMATTER "-----~2%~
;           ~{~&~1&~
;           ~[~^~:;~
;           ~1:*~@(~
;           ~R~) bo~
;          ttle~:P o~
;         f beer on t~
;       he wall~01:*~[.~
;       ~:;,~%~1:*~@(~R~
;       ~) bottle~:*~P ~
;       of beer.~%You t~
;       ake one down, p~
;       ass it around, ~
;       ~01%~[*No* more~
;       ~:;~:01*~@(~R~)~
;       ~] bottle~:*~P ~
;       of beer on the ~
;       wall.~2&-----~%~
;       ~1%~:*~]~]~}~0%")
;           #:G7)
; 
; note: The second argument never returns a value.

; compiling (BOTTLE-SONG); 
; compilation unit finished
;   caught 1 ERROR condition
;   caught 1 WARNING condition
;   printed 1 note


; /home/N6mIUx/prog.fasl written
; compilation finished in 0:00:00.128
Unhandled SIMPLE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                    {1001E07133}>:
  compilation failed

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1001E07133}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SIMPLE-ERROR "compilation failed" {1001FA6E03}> #<unavailable argument>)
1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SIMPLE-ERROR "compilation failed" {1001FA6E03}>)
2: (INVOKE-DEBUGGER #<SIMPLE-ERROR "compilation failed" {1001FA6E03}>)
3: (ERROR "compilation failed")
4: (SB-INT:SIMPLE-EVAL-IN-LEXENV (ERROR "compilation failed") #<NULL-LEXENV>)
5: (SB-INT:SIMPLE-EVAL-IN-LEXENV (WHEN (NTH-VALUE 2 (COMPILE-FILE "prog.lisp")) (ERROR "compilation failed")) #<NULL-LEXENV>)
6: (EVAL (WHEN (NTH-VALUE 2 (COMPILE-FILE "prog.lisp")) (ERROR "compilation failed")))
7: (SB-IMPL::PROCESS-EVAL/LOAD-OPTIONS ((:EVAL . "(when(nth-value 2(compile-file \"prog.lisp\"))(error \"compilation failed\"))") (:EVAL . "(quit)")))
8: (SB-IMPL::TOPLEVEL-INIT)
9: ((FLET #:WITHOUT-INTERRUPTS-BODY-77 :IN SAVE-LISP-AND-DIE))
10: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))

unhandled condition in --disable-debugger mode, quitting
stdout
Standard output is empty