Expanded dlambda example

This commit is contained in:
Mike Cifelli 2017-03-02 10:29:59 -05:00
parent 2bd0c1a674
commit ef4c03a672
2 changed files with 69 additions and 17 deletions

View File

@ -8,20 +8,76 @@
(eval (eval
(dlambda (dlambda
(:inc-apple () (setf apple-count (+ apple-count 1)))
(:dec-apple () (setf apple-count (- apple-count 1))) (:inc-apple ()
(:get-apple () apple-count) (setf apple-count (+ apple-count 1))
(:set-apple (value) (setf apple-count value)) )
(:inc-banana () (setf banana-count (+ banana-count 1)))
(:dec-banana () (setf banana-count (- banana-count 1))) (:dec-apple ()
(:get-banana () banana-count) (setf apple-count (- apple-count 1))
(:set-banana (value) (setf banana-count (- banana-count 1))) )
(:inc-coconut () (setf coconut-count (+ coconut-count 1)))
(:dec-coconut () (setf coconut-count (- coconut-count 1))) (:get-apple ()
(:get-coconut () coconut-count) apple-count
(:set-coconut (value) (setf coconut-count value)) )
(:set-apple (value)
(setf apple-count value)
)
(:inc-banana ()
(setf banana-count (+ banana-count 1))
)
(:dec-banana ()
(setf banana-count (- banana-count 1))
)
(:get-banana ()
banana-count
)
(:set-banana (value)
(setf banana-count value)
)
(:inc-coconut ()
(setf coconut-count (+ coconut-count 1))
)
(:dec-coconut ()
(setf coconut-count (- coconut-count 1))
)
(:get-coconut ()
coconut-count
)
(:set-coconut (value)
(setf coconut-count value)
)
) )
) )
) )
) )
; Create an instance
;
; usage:
; ~ (my-counter :set-apple 23)
; 23
;
(let ((instance (fruit-counter 0)))
(defun my-counter (&rest args) (apply instance args))
)
; Another way
;
; usage:
; ~ (funcall my-counter2 :set-apple 23)
; 23
;
(setf my-counter2 (fruit-counter 10000))

View File

@ -47,7 +47,7 @@ public class CASE extends LispSpecialFunction {
else if (keyList.isCons()) else if (keyList.isCons())
return containsMatch(key, keyList); return containsMatch(key, keyList);
return isEqual(key, keyList) || isKeyListT(keyList); return isEqual(key, keyList) || isEqual(T, keyList);
} }
private boolean containsMatch(SExpression key, SExpression keyList) { private boolean containsMatch(SExpression key, SExpression keyList) {
@ -58,10 +58,6 @@ public class CASE extends LispSpecialFunction {
return false; return false;
} }
private boolean isKeyListT(SExpression keyList) {
return isEqual(T, keyList);
}
private SExpression advanceCons(SExpression knownCons) { private SExpression advanceCons(SExpression knownCons) {
return ((Cons) knownCons).getRest(); return ((Cons) knownCons).getRest();
} }