[plt-scheme] Y

From: Jos Koot (jos.koot at telefonica.net)
Date: Sun Jan 27 20:02:45 EST 2008

For who likes it.
A probably useless but funny applicative-order Y-combinator for arbitrary numbers of mutual dependent procedures of arbitrary arities:

(lambda ms
 (apply values
  ((lambda (c)
    ((lambda (e) (map e ms))
     (lambda (m) (apply (c m) (map c ms)))))
   (lambda (m)
    (lambda fs
     (apply m
      (map
       (lambda (f)
        (lambda xs (apply (apply f fs) xs)))
       fs)))))))

It took me some labour to concoct this thing.
A useless example:

(let-values
 (((triple? triple+1? triple+2?)
   (y ; insert the above procedure
    (lambda (triple? triple+1? triple+2?)
     (lambda (x)
      (or (zero? x) (triple+2? (sub1 x) 'ignored)))) ; multiple of 3 + 0
    (lambda (triple? triple+1? triple+2?)
     (lambda (x)
      (and (not (zero? x)) (triple? (sub1 x))))) ; multiple of 3 + 1
    (lambda (triple? triple+1? triple+2?)
     (lambda (x ignored)
      (and (not (zero? x)) (triple+1? (sub1 x))))))))
  (triple? 100002)) ;--> #t


Jos koot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080128/17132e22/attachment.html>

Posted on the users mailing list.