インタプリタとは
(define (tashizan-interpreter)
  (define (base-eval exp)
    (cond ((number? exp) exp)
          ((and (pair? exp) (eq? (car exp) 'tashizan))
             (+ (base-eval (cadr exp)) (base-eval (caddr exp))))
          (else "syntax error")))
  (display " ")
  (let ((answer (base-eval (read))))  ; ここで入力待ち
    (display "= ")
    (write answer))
  (newline)
  (tashizan-interpreter))
> (tashizan-interpreter)
 (tashizan 1 (tashizan 2 3))
= 6
 (+ 1 2)
= "syntax error"

一覧 前へ 次へ