Lambda Calculus CONS Pair implementation with Lisp

 ̄綄美尐妖づ 提交于 2019-12-24 14:41:17

问题


I'm trying to implement a Church Pair Lambda Calc. style with CLisp.

According with Wikipedia:

pair ≡ λx.λy.λz.z x y

So far, this is my code:

 (defvar PAIR
         #'(lambda(x)
                 #'(lambda(y)
                         #'(lambda(z)
                                 (funcall (funcall z x) y)))) )

These are my FIRST and SECOND Functions:

(defvar FIRST
        #'(lambda(p)
                (funcall(p TRUE)))
)

(defvar SECOND
        #'(lambda(p)
                (funcall(p FALSE)))
)

This 2 functions convert from Int to ChurchNumber

(defun church2int(numchurch)
    (funcall (funcall numchurch #'(lambda (x) (+ x 1))) 0)
)

(defun int2church(n)
    (cond
        ((= n 0) #'(lambda(f) #'(lambda(x)x)))
        (t #'(lambda(f) #'(lambda(x) (funcall f
            (funcall(funcall(int2church (- n 1))f)x))))))

)

So, what I do is:

(setq six (int2church 6))
(setq four (int2church 4))

And then:

(setq P (funcall (funcall PAIR six) four))

And the I've got:

#<FUNCTION :LAMBDA (Y) (FUNCALL (FUNCALL F X) Y)>

So if I do this:

(funcall #'FIRST P)

I've got the this error:

*** - FIRST: #<FUNCTION :LAMBDA (Y) (FUNCALL (FUNCALL F X) Y)> is not a list

I can't see what I am doing wrong. Any help would be appreciated.

Thanks


回答1:


We understand there are some folks upset about the decision made this week. We aren’t going to share specifics out of respect for all individuals involved but this is a site reaching millions of people and we have to do what we believe fosters a spirit of inclusion and respect. When a moderator violates that, we will always do our best to resolve it with them privately. When we can’t we must take action. This is always done based on what we believe is best for all SE users.



来源:https://stackoverflow.com/questions/13537622/lambda-calculus-cons-pair-implementation-with-lisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!