[Scheme]循环读入并计算数字之和

阅读更多
一段guile脚本文件,循环读入并计算从stdin输入的两个数之和。
#!/usr/local/bin/guile -s
!#

(define (main)
 (let ((a (read (current-input-port)))
       (b (read (current-input-port))))
  (if (not (eof-object? a))
   (begin
    (write (+ a b) (current-output-port))
    (write-char #\newline (current-output-port))
    (main)))))
(main)

你可能感兴趣的:(scheme)