2011-09-11 19 views

cevap

6
(defun example() 
    (let ((a 0) 
     (f nil)) 
    (macrolet ((next (state) 
       `(setf f (function ,state)))) 
     (labels ((init() 
       (setf a 0) 
       (next inc)) 
       (inc() 
       (incf a) 
       (next inc) 
       (when (> a 5) 
        (next reset))) 
       (reset() 
       (setf a 0) 
       (next inc)) 
       (controller() 
       (funcall f) 
       (print a))) 
     (init) 
     (loop repeat 20 
       do (controller)))))) 

Örnek çağrı:

CL-USER 7 > (example) 

1 
2 
3 
4 
5 
6 
0 
1 
2 
3 
4 
5 
6 
0 
1 
2 
3 
4 
5 
6 
NIL 
+0

teşekkürler! ne yapmak istediğimde sadece init çağrılmasaydım? – gumbo

+0

Bu, "etiketler" in bazı basit ve kolay açıklamasında yardımcı olabilir. –