transcendental-lisp/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodObject.wiki

26 lines
858 B
Plaintext
Raw Normal View History

2017-03-02 16:36:23 -05:00
---
Test
---
An object with multiple methods.
| script | lisp interpreter fixture |
| show | evaluate |!-
(defun counter-class ()
(let ((counter 0))
(lambda (msg)
(case msg
((:inc)
(setq counter (+ counter 1)))
((:dec)
(setq counter (- counter 1)))))))
-!|
| show | evaluate | (setq my-counter (counter-class)) |
| 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 |