(defun fixpoint ( x y)
(funcall y (funcall x x y) )
)
(defun try ( f check init)
(if (funcall check (funcall f init) init )
init
(progn
(print init)
(try f check (funcall f init) )
)
)
)
(setq fun (fixpoint 'fixpoint
(lambda (s)
(lambda ( f check init)
(if (funcall check (funcall f init) init )
init
(progn
(print init)
(funcall s f check (funcall f init) )
)
)
)
)
)
)
(funcall fun (lambda(x)(sin x) )
(lambda (x y)(if (< (abs (- x y)) (/ 1 10000) ) t nil)) (/ 1 11) )
本文探讨了Lisp语言中通过递归函数实现固定点运算的过程。利用Lisp的强大元编程能力,定义了一个名为`fixpoint`的递归函数,并在此基础上实现了无限递归查找稳定状态的尝试函数`try`。此外,还展示了如何使用这些函数来逼近数学函数(如正弦函数)的不动点。
1246

被折叠的 条评论
为什么被折叠?



