列表 4. C 风格的 chomp 函数

(define (chomp string)
  (substring string 0
             ;; start at the end of the string and work backward
        (let loop ((len (string-length string)))
        ;; recurse until we have the number of the last
        ;; non-newline character
        (if (and (> len 0)
                      (lineterm? (string-ref string (- len 1))))
       (loop (- len 1))
       len))))
© . All rights reserved.