From: Marc Heijligers
Subject: Lambda Calculus and MACL
Date:
Message-ID: <484@al.ele.tue.nl>
I am interested in lambda calculus, and I was trying some functions
I found in the Common LISP the reference manual of Franz Inc.
The functions I tried can be found on page 46 and 47:
(defun Y (h)
"The fixpoint combinator Y of the lambdacalculus.
Returns the fixed point of its functional argument."
(funcall
#'(lambda (x)
#'(lambda (g)
(funcall (funcall h (funcall x x)) g)))
#'(lambda (x)
#'(lambda (g)
(funcall (funcall h (funcall x x)) g)))))
(defun fac (n)
(funcall
'#,(Y #'(lambda (f)
#'(lambda (n)
(if (zerop n) 1 (* n (funcall f (1- n)))))))))
I tried to call (fac 2), but I got the following error (in MACL):
> Error: Too few arguments to NIL .
> While executing: #<An Anonymous Compiled Function>
Can anyone explain why this doesn't work?
Marc Heijligers
······@ele.tue.nl
From: Carl Klapper
Subject: Re: Lambda Calculus and MACL
Date:
Message-ID: <1460@oravax.UUCP>
In article <···@al.ele.tue.nl>, ······@ele.tue.nl (Marc Heijligers) writes:
> (defun Y (h)
> "The fixpoint combinator Y of the lambdacalculus.
> Returns the fixed point of its functional argument."
> (funcall
> #'(lambda (x)
> #'(lambda (g)
> (funcall (funcall h (funcall x x)) g)))
> #'(lambda (x)
> #'(lambda (g)
> (funcall (funcall h (funcall x x)) g)))))
>
> (defun fac (n)
> (funcall
> '#,(Y #'(lambda (f)
> #'(lambda (n)
> (if (zerop n) 1 (* n (funcall f (1- n)))))))))
>
> I tried to call (fac 2), but I got the following error (in MACL):
> > Error: Too few arguments to NIL .
> > While executing: #<An Anonymous Compiled Function>
'#,(Y #'(lambda (f)
#'(lambda (n)
(if (zerop n) 1 (* n (funcall f (1- n)))))))
expects an argument, namely the n from the argument list of fac.
Try
(defun fac (n)
(funcall
(Y #'(lambda (f) #'(lambda (m)
(if (zerop m)
1
(* m (funcall f (1- m)))))))
n))
instead.
> Marc Heijligers
> ······@ele.tue.nl
+-----------------------------+--------------------------------------------+
| Real urbanites don't buy | Carl Klapper |
| things. They buy service. | Odyssey Research Associates, Inc. |
| | 301A Harris B. Dates Drive |
| A kitchen's place is | Ithaca, NY 14850 |
| in the restaurant. | (607) 277-2020 |
| | ···················@cu-arpa.cs.cornell.edu |
+-----------------------------+--------------------------------------------+