CONS形式化 (一般化)

来源:互联网 发布:html个人网页源码 编辑:程序博客网 时间:2024/05/29 17:35

(defun  mycons (x y)

(lambda ( s z)

(funcall (funcall s  x  y )  z)

)

)

 

(defun wrapcar (s)

(lambda  (a b)

(lambda (z)

(funcall a s  z)

)

)

)

 

(defun  mycar (n)

(lambda (s z)

(funcall  n (wrapcar s )  z) 

)

)

 

(defun wrapcdr (s)

(lambda  (a b)

(lambda (z)

(funcall b s  z)

)

)

)

 

 

(defun  mycdr (n)

(lambda (s z)

(funcall  n  (wrapcdr s ) z) 

)

)

 

 

(setq  one  (lambda (s z) (funcall  s z) ))

(setq  two  (lambda (s z) (funcall s (funcall  s z) )))

(setq  three  (lambda (s z) (funcall s (funcall s (funcall  s z) ))))

 

(defun chenbing (value)

(list  'chenbing value)

)

 

(funcall one 'chenbing nil)

(funcall two 'chenbing nil)

(funcall three 'chenbing nil)

 

(setq  a  (mycons    two one) )

(setq  b  (mycons  three a) )

 

 

(funcall (mycar  a) 'chenbing nil)

(funcall (mycar  b) 'chenbing nil)