3 ms·
I've tried to create Y combinator in common-lisp, but I get errors with this: ----------------- (defun Y (r) (funcall #'(lambda (f) (funcall
by yarek 18y ago
I've tried to create Y combinator in common-lisp, but I get errors with this:
-----------------
(defun Y (r)
(funcall #'(lambda (f)
(funcall f f))
#'(lambda (f)
(funcall r #'(lambda (x)
(funcall (funcall f f) x))))))
(defun fact-gen (fact-in)
#'(lambda (n)
(if (eq n 0) 1
(* n (funcall fact-in (- n 1))))))
(funcall (Y #'fact-gen) 1)
-----------------
Any suggestions? Thanks!
- newt0311 18y agoWorks for me. Using SBCL 1.0.14-gentoo on x86. Which common lisp runtime are you using? And yeah... Lisp-2 is a stupid idea.
- yarek 18y agoOops, messed my linux instance somehow. Works fine on the fresh instance of SBCL-x86-64 1.20. As to Lisp-2, dude that's a debate that I don't want to get into. :) I'm just happy I can use any kind of Lisp -- the rest is just details. Yarek
- parenthesis 18y agoPlease don't conclude that lisp-2 is a bad idea until you've considered that: • there are disadvantages as well as advantages to lisp-1; and • there is nothing about lisp-2-ness itself that requires the verbosity of (funcall #'…)-ing in Common Lisp: Firstly, even in Common Lisp, (funcall (lambda …) …) and (funcall 'car list) are valid. (And many implementations allow ((lambda …) …) — though I can't remember whether the standard defines this.) Secondly, funcall can be renamed something shorter (e.g. fun). And finally, for those lispers not against a little syntax, a lisp-2 could define some syntax so that one could write, e.g. (#f …) for (funcall f …) and (##f …) for (funcall 'f …). Then the above code would be: (defun Y (r) ((lambda (f) (#f f)) (lambda (f) (#r (lambda (x) (fun (#f f) x)))))) etc.. (And we can make it even shorter if we call lambda something shorter, e.g. fn.)
- newt0311 18y agoAlready have: http://www.nhplace.com/kent/Papers/Technical-Issues.html http://www.nhplace.com/kent/Papers/Technical-Issues.html
- jockc 18y agoworks for me in ACL 8.1