aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-07-01 12:10:11 +0800
committerMistivia <i@mistivia.com>2025-07-01 12:10:11 +0800
commit7dfaa40719c5a264b17aca96cd85e31bf7b8b557 (patch)
tree17c2cb2919393fc89620efb38495121950cf77cf /tests
parent6d89e9697b1740366f23387964122d264475b49c (diff)
extend defun
Diffstat (limited to 'tests')
-rw-r--r--tests/lambda.lisp22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/lambda.lisp b/tests/lambda.lisp
index 759a217..c7337ba 100644
--- a/tests/lambda.lisp
+++ b/tests/lambda.lisp
@@ -3,15 +3,12 @@
(lambda (g) (funcall g g))
(lambda (h)
(funcall f (lambda args (apply (funcall h h) args))))))
-
(defun fibo-impl (self)
(lambda (n)
(if (<= n 2)
1
(+ (funcall self (- n 1)) (funcall self (- n 2))))))
-
(defvar fibo (Y #'fibo-impl))
-
(assert (= 55 (funcall fibo 10)))
(defun generate-counter (init)
@@ -19,7 +16,6 @@
(lambda ()
(setq i (+ 1 i))
i)))
-
(let ((c (generate-counter 0)))
(assert (= 1 (funcall c)))
(assert (= 2 (funcall c)))
@@ -37,3 +33,21 @@
((f
(lambda (x) (funcall f 1) x)))
(funcall f 1)))
+
+(defun my-add (lambda (x y) (+ x y)))
+(assert (= 3 (my-add 1 2)))
+
+(defun my-add #'+)
+(assert (= 3 (my-add 1 2)))
+
+(defvar flag 0)
+(defun func ()
+ (incq flag)
+ (incq flag))
+(defun func
+ (let ((old-func #'func))
+ (lambda ()
+ (funcall old-func)
+ (incq flag))))
+(func)
+(assert (= 3 flag))