[Openmcl-devel] A plug for nx1-combination-hook

Ron Garret ron at flownet.com
Thu Sep 3 15:57:55 PDT 2009


On Sep 3, 2009, at 3:15 PM, Glen Foy wrote:

>
> On Sep 3, 2009, at 5:49 PM, Gary Byers wrote:
>
>> Glen's file seemed to actually be encoded in Macintosh (aka  
>> MacRoman).
>> If you mistakenly try to interpret MacRoman (or UTF-8, or lots of
>> other encodings) as ISO-8859-1, you get some of the characters wrong
>> (the ellipsis looks like an acute-accented #\E, etc.) but don't run
>> the risk of getting out-of-synch and confused.
>
>
> I've converted the contribs to UTF-8 and removed the offending odd
> chars: an ellipsis char, a copyright char and a bullet char.
>
> Ron's technique of using the letter lambda as opposed to the word is
> what convinced me.  We have to consider the cool factor, here!

As long as Glen brought up the cool factor I'd like to float another  
trial balloon.

I have this little hack that allows CCL to support ((...) ...)  
syntax.  Source code is at:

http://www.flownet.com/ron/lisp/nx1-combination-hook.lisp

When you load this code you can do Scheme-like things without a ton of  
funcalls.  In particular, with a suitable definition of λ and DEFINE  
(about 15 LOC) you can build a really clean-looking Y-combinator.   
Instead of this:

(defun y (f) (funcall (lambda (g) (funcall g g)) (lambda (h) (lambda  
(x) (funcall (funcall f (funcall h h)) x)))))
(defun fact* (f) (lambda (n) (if (zerop n) 1 (* n (funcall f (1- n))))))
(funcall (y fact*) 15)

you can now write this:

(define y (λ (f) ((λ (g) (g g)) (λ (h) (λ (x) ((f (h h)) x))))))
(define fact* (λ (f) (λ (n) (if (zerop n) 1 (* n (f (1- n)))))))
((y fact*) 15)

It actually works:

? (define y (λ (f) ((λ (g) (g g)) (λ (h) (λ (x) ((f (h h)) x))))))
Y
? (define fact* (λ (f) (λ (n) (if (zerop n) 1 (* n (f (1- n)))))))
FACT*
? ((y fact*) 15)
1307674368000
?


IMHO, being able to actually run the more compact form would be a big  
win for pedagogical purposes if nothing else.  I think it would also  
potentially win some converts who might be on the fence between CL and  
Scheme.  (And if we can integrate H-M type-checking we might win some  
Haskell wannabes as well. :-)

This is not possible in portable CL because the CL standard requires  
that ((X ...) ...) to be an error if X is anything other than  
'LAMBDA.  Note that despite the fact that this allows CCL to produce  
behavior that is in technical violation of the standard it would not  
actually make CCL a non-conforming implementation.  This is because  
nx1-combination-hook, as the name implies, doesn't actually *change*  
the bahvior of ((...) ...), it merely introduces a hook through which  
the user at their option may change the behavior.

So... would anyone object to having nx1-combination-hook added as an  
extension to the stock CCL code?

rg




More information about the Openmcl-devel mailing list