Expanded dlambda example
This commit is contained in:
parent
2bd0c1a674
commit
ef4c03a672
|
@ -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))
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue