[Openmcl-devel] What is the new context argument in all the compiler functions?
Ron Garret
ron at flownet.com
Mon Apr 23 19:25:58 PDT 2012
I figured out a workaround for this that should be robust against future changes in the API.
In case anyone is interested, the code is here:
http://www.flownet.com/ron/lisp/combination-hook.lisp
It lets you do things like compute a factorial using an inline Y-combinator:
? (((λ (f) ((λ (g) (g g)) (λ (h) (λ (x) ((f (h h)) x)))))
(λ (f) (λ (n) (if (zerop n) 1 (* n (f (1- n)))))))
15)
1307674368000
Or compute factorial of 6 using Church numerals:
? ((((λ (f) ((λ (g) (g g)) (λ (h) (λ (x) ((f (h h)) x)))))
(λ (f)
(λ (n)
(if ((λ (p a b) (p a b)) ((λ (n) (n (λ (x) (λ (x y) y)) (λ (x y) x))) n) t nil)
((λ (n) (λ (f x) (f (n f x)))) (λ (f x) x))
((λ (m n) (m ((λ (m n) (λ (f x) (m f (n f x)))) n) (λ (f x) x)))
n (f ((λ (n) (λ (f x) (n (λ (g h) (h (g f))) (λ (u) x) (λ (u) u)))) n)))))))
((λ (n) (λ (f x) (f (n f x))))
((λ (n) (λ (f x) (f (n f x))))
((λ (n) (λ (f x) (f (n f x))))
((λ (n) (λ (f x) (f (n f x))))
((λ (n) (λ (f x) (f (n f x))))
((λ (n) (λ (f x) (f (n f x))))
(λ (f x) x))))))))
'1+ 0)
720
Reasonable people could disagree, but I think this is pretty cool.
rg
On Apr 23, 2012, at 12:59 PM, Ron Garret wrote:
>
> On Apr 23, 2012, at 11:55 AM, Gary Byers wrote:
>
>> I'm spmewhat dismayed that changes like this don't happen more often
>> than they do. There are lots of reasons for that, but worrying about
>> whether someone will be "somwhat dismayed" when private internal interfaces
>> change isn't and can't be one of them.
>
> I completely agree, but there is an extenuating circumstance in this case.
>
> One of my interests is pedagogy. When writing code to illustrate how Lisp is derived from the lambda calculus I often find it useful to use ((...) ...) as a shorthand for (funcall (...) ...). So a while back I requested that the last line of nx1-combination be changed from:
>
> (nx-error "In the form ~S, ~S is not a symbol or lambda expression." form sym)))))
>
> to something like:
>
> ...
> (nx-combination-hook form sym)))))
>
> (defun nx-combination-hook (form sym)
> (nx-error "In the form ~S, ~S is not a symbol or lambda expression." form sym))
>
> so that a user could change this behavior.
>
> You denied this request (as of course is your prerogative) and instead suggested that I use ADVISE to change the behavior of NX1-COMBINATION, which I did, and everyone went home happy. But changing the interface to NX1-COMBINATION breaks my ADVISE code (because it has to call back in to nx1-combination).
>
> I'm not saying that you should feel obligated to do anything about this. I was just surprised that this part of the compiler was changed and wondered why it happened. I also wanted you to be aware of the situation in case you were feeling charitable, or had another suggestion.
>
> rg
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
More information about the Openmcl-devel
mailing list