2017-02-28 11:54:19 -05:00
|
|
|
---
|
|
|
|
Test
|
|
|
|
---
|
|
|
|
| script | lisp interpreter fixture |
|
|
|
|
| # | Object with multiple methods |
|
|
|
|
| show | evaluate |!-
|
|
|
|
|
2017-03-01 11:11:59 -05:00
|
|
|
(defun counter-class ()
|
2017-02-28 11:54:19 -05:00
|
|
|
(let ((counter 0))
|
|
|
|
(lambda (msg)
|
|
|
|
(case msg
|
|
|
|
((:inc)
|
|
|
|
(setq counter (+ counter 1)))
|
|
|
|
((:dec)
|
|
|
|
(setq counter (- counter 1)))))))
|
|
|
|
|
|
|
|
-!|
|
2017-03-01 11:11:59 -05:00
|
|
|
| show | evaluate | (setq my-counter (counter-class)) |
|
2017-02-28 11:54:19 -05:00
|
|
|
| check | evaluate | (funcall my-counter :inc) | 1 |
|
|
|
|
| check | evaluate | (funcall my-counter :inc) | 2 |
|
|
|
|
| check | evaluate | (funcall my-counter :inc) | 3 |
|
|
|
|
| check | evaluate | (funcall my-counter :dec) | 2 |
|
|
|
|
| check | evaluate | (funcall my-counter :dec) | 1 |
|
|
|
|
| check | evaluate | (funcall my-counter :dec) | 0 |
|
2017-03-01 16:33:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
| script | lisp interpreter fixture |
|
|
|
|
| # | dlambda |
|
|
|
|
| show | evaluate |!-
|
|
|
|
|
|
|
|
(defun map (fn ls)
|
|
|
|
(if (null ls)
|
|
|
|
()
|
|
|
|
(cons (funcall fn (first ls))
|
|
|
|
(map fn (rest ls))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define-macro dlambda (&rest methods)
|
|
|
|
(cons
|
|
|
|
(quote lambda)
|
|
|
|
(cons
|
|
|
|
(quote (&rest arguments))
|
|
|
|
(list
|
|
|
|
(cons
|
|
|
|
(quote case)
|
|
|
|
(cons
|
|
|
|
(quote (first arguments))
|
|
|
|
(map
|
|
|
|
(lambda (method)
|
|
|
|
(cons
|
|
|
|
(first method)
|
|
|
|
(list
|
|
|
|
(cons
|
|
|
|
(quote apply)
|
|
|
|
(cons
|
|
|
|
(cons
|
|
|
|
(quote lambda)
|
|
|
|
(rest method)
|
|
|
|
)
|
|
|
|
(list (quote (rest arguments)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
methods
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(defun apple-counter ()
|
|
|
|
(let ((apple-count 0))
|
|
|
|
(eval
|
|
|
|
(dlambda
|
|
|
|
(:inc () (setf apple-count (+ apple-count 1)))
|
|
|
|
(:dec () (setf apple-count (- apple-count 1)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
-!|
|
|
|
|
| show | evaluate | (setf a (apple-counter)) |
|
|
|
|
| check | evaluate | (funcall a :inc) | 1 |
|
|
|
|
| check | evaluate | (funcall a :inc) | 2 |
|
|
|
|
| check | evaluate | (funcall a :inc) | 3 |
|
|
|
|
| check | evaluate | (funcall a :dec) | 2 |
|
|
|
|
| check | evaluate | (funcall a :dec) | 1 |
|
|
|
|
| check | evaluate | (funcall a :dec) | 0 |
|
|
|
|
| show | evaluate | (funcall a :inc 1) |
|