Comment detail

/*コメント*/を取り除く (Nested Flatten)
「なんでも再帰」の相互再帰で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(define (remove-comment s)
  (define (out-comment c)
    (cond ((eof-object? c))
          ((char=? c #\/)
           (cond ((eof-object? (peek-char))
                  (display c))
                 (else
                  (cond ((char=? (peek-char) #\*)
                         (read-char)
                         (in-comment (read-char)))
                        (else
                         (display c)
                         (out-comment (read-char)))))))
          (else
           (display c)
           (out-comment (read-char)))))
  (define (in-comment c)
    (cond ((eof-object? c))
          ((char=? c #\*)
           (unless (eof-object? (peek-char))
             (cond ((char=? (peek-char) #\/)
                    (read-char)
                    (out-comment (read-char)))
                   (else
                    (in-comment (read-char))))))
          (else
           (in-comment (read-char)))))
  (with-output-to-string
      (lambda ()
        (with-input-from-string s
          (lambda () (out-comment (read-char)))))))

Index

Feed

Other

Link

Pathtraq

loading...