2017-03-02 16:36:23 -05:00
|
|
|
---
|
|
|
|
Test
|
|
|
|
---
|
|
|
|
Shows the usage of a static variable.
|
|
|
|
''"Let Over Lambda Over Let Over Lambda"''
|
|
|
|
|
|
|
|
| script | lisp interpreter fixture |
|
2017-03-06 12:44:06 -05:00
|
|
|
| show | evaluate text | !-
|
2017-03-02 16:36:23 -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-03-06 12:44:06 -05:00
|
|
|
-!|
|
|
|
|
| show | evaluate text | (setq my-counter (counter-class)) |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 1 |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 2 |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 3 |
|
|
|
|
| show | evaluate text | (toggle-counter-direction) |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 2 |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 1 |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 0 |
|
|
|
|
| show | evaluate text | (toggle-counter-direction) |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 1 |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 2 |
|
|
|
|
| check | evaluate text | (funcall my-counter) | 3 |
|