2017-02-27 12:00:24 -05:00
|
|
|
---
|
|
|
|
Test
|
|
|
|
---
|
|
|
|
| script | lisp interpreter fixture |
|
2017-02-27 13:34:04 -05:00
|
|
|
| show | evaluate | (defun adderx (x) (lambda (y) (+ x y))) |
|
|
|
|
| show | evaluate | (setf adder20 (adderx 20)) |
|
2017-02-27 12:00:24 -05:00
|
|
|
| check | evaluate | (funcall adder20 2) | 22 |
|
|
|
|
|
|
|
|
|
|
|
|
| script | lisp interpreter fixture |
|
2017-02-27 13:34:04 -05:00
|
|
|
| # | Let Over Lambda Over Let Over Lambda |
|
|
|
|
| show | evaluate |!-
|
2017-02-27 12:00:24 -05:00
|
|
|
|
|
|
|
(let ((direction 'up))
|
|
|
|
(defun toggle-counter-direction ()
|
|
|
|
(setq direction
|
|
|
|
(if (eq direction 'up)
|
|
|
|
'down
|
|
|
|
'up)))
|
|
|
|
|
|
|
|
(defun counter-class ()
|
|
|
|
(let ((counter 0))
|
|
|
|
(lambda ()
|
|
|
|
(if (eq direction 'up)
|
|
|
|
(setq counter (+ counter 1))
|
|
|
|
(setq counter (- counter 1)))))))
|
2017-02-27 13:34:04 -05:00
|
|
|
-!|
|
|
|
|
| show | evaluate | (setq my-counter (counter-class)) |
|
2017-02-27 12:00:24 -05:00
|
|
|
| check | evaluate | (funcall my-counter) | 1 |
|
|
|
|
| check | evaluate | (funcall my-counter) | 2 |
|
|
|
|
| check | evaluate | (funcall my-counter) | 3 |
|
2017-02-27 13:34:04 -05:00
|
|
|
| show | evaluate | (toggle-counter-direction) |
|
2017-02-27 12:00:24 -05:00
|
|
|
| check | evaluate | (funcall my-counter) | 2 |
|
|
|
|
| check | evaluate | (funcall my-counter) | 1 |
|
|
|
|
| check | evaluate | (funcall my-counter) | 0 |
|
2017-02-27 13:34:04 -05:00
|
|
|
| show | evaluate | (toggle-counter-direction) |
|
2017-02-27 12:00:24 -05:00
|
|
|
| check | evaluate | (funcall my-counter) | 1 |
|
|
|
|
| check | evaluate | (funcall my-counter) | 2 |
|
|
|
|
| check | evaluate | (funcall my-counter) | 3 |
|