Debian Codegraph @

tests/inputs/sharpsign.cl

raw
1 ;;; In this example, some debugging code is commented out with #|...|#
2 ;;; Note that this kind of comment can occur in the middle of a line
3 ;;; (because a delimiter marks where the end of the comment occurs)
4 ;;; where a semicolon comment can only occur at the end of a line
5 ;;; (because it comments out the rest of the line).
6 (defun add3 (n) #|(format t "~&Adding 3 to ~D." n)|# (+ n 3))
7
8 ;;; The examples that follow show issues related to #| ... |# nesting.
9
10 ;;; In this first example, #| and |# always occur properly paired,
11 ;;; so nesting works naturally.
12 (defun mention-fun-fact-1a ()
13 (format t "CL uses ; and #|...|# in comments."))
14 => MENTION-FUN-FACT-1A
15 (mention-fun-fact-1a)
16 >> CL uses ; and #|...|# in comments.
17 => NIL
18 #| (defun mention-fun-fact-1b ()
19 (format t "CL uses ; and #|...|# in comments.")) |#
20 (fboundp 'mention-fun-fact-1b) => NIL
21
22 ;;; In this example, vertical-bar followed by sharpsign needed to appear
23 ;;; in a string without any matching sharpsign followed by vertical-bar
24 ;;; having preceded this. To compensate, the programmer has included a
25 ;;; slash separating the two characters. In case 2a, the slash is
26 ;;; unnecessary but harmless, but in case 2b, the slash is critical to
27 ;;; allowing the outer #| ... |# pair match. If the slash were not present,
28 ;;; the outer comment would terminate prematurely.
29 (defun mention-fun-fact-2a ()
30 (format t "Don't use |\# unmatched or you'll get in trouble!"))
31 => MENTION-FUN-FACT-2A
32 (mention-fun-fact-2a)
33 >> Don't use |# unmatched or you'll get in trouble!
34 => NIL
35 #| (defun mention-fun-fact-2b ()
36 (format t "Don't use |\# unmatched or you'll get in trouble!") |#
37 (fboundp 'mention-fun-fact-2b) => NIL
38
39 ;;; In this example, the programmer attacks the mismatch problem in a
40 ;;; different way. The sharpsign vertical bar in the comment is not needed
41 ;;; for the correct parsing of the program normally (as in case 3a), but
42 ;;; becomes important to avoid premature termination of a comment when such
43 ;;; a program is commented out (as in case 3b).
44 (defun mention-fun-fact-3a () ; #|
45 (format t "Don't use |# unmatched or you'll get in trouble!"))
46 => MENTION-FUN-FACT-3A
47 (mention-fun-fact-3a)
48 >> Don't use |# unmatched or you'll get in trouble!
49 => NIL
50 #|
51 (defun mention-fun-fact-3b () ; #|
52 (format t "Don't use |# unmatched or you'll get in trouble!"))
53 |#
54 (fboundp 'mention-fun-fact-3b) => NIL
55