LISP Scheme

このエントリーをはてなブックマークに追加
9689
>>90のMIT風の書き方の方
(cond->caseしただけですが)
(define (make-shape newx newy)
 (let (
  (x newx)
  (y newy))
  (lambda (method parms)
   (case method ; accessors for x & y
    ((getx) x)
    ((gety) y)
    ((setx) (set! x parms))
    ((sety) (set! y parms)) ; move the x & y coordinates
    ((moveto)
     (set! x (car parms))
     (set! y (car (cdr parms))))
    ((rmoveto)
     (set! x (+ x (car parms)))
     (set! y (+ y (car (cdr parms)))))
    (else (no-method))))))
letの辺りはよく分かりませんが、これをマクロでテンプレートにしたら
結構使えそうです。