Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. ;; I'm hitting my head against a wall trying to implement the Y Combinator in SKI in Clojure
  2. ;; Anyone with experience implementing it, or is able to detect what's wrong here?
  3.  
  4. (defn I [x] x)
  5. #_=> #'user/I
  6. (def K (fn [x] (fn [y] x)))
  7. #_=> #'user/K
  8. (def S (fn [x] (fn [y] (fn [z] ((x z)(y z))))))
  9. #_=> #'user/S
  10. ;; The culprit:
  11. (def Y ((S (K ((S I) I))) ((S ((S (K S)) K)) (K ((S I) I)))))
  12. #_=> #'user/Y
  13. ;; fac work fine with a straight port of the Y combinator in Clojure,
  14. ;; so this one is probably not the issue.
  15. (def fac (fn [f] (fn [n] (if (zero? n) 1 (* n (f (dec n)))))))
  16. #_=> #'user/fac
  17. ((Y fac) 10)
  18.  
  19. ;; StackOverflowError user/S/fn--844/fn--845 (NO_SOURCE_FILE:1)
  20. ((Y fac) 1)
  21.  
  22. ;; StackOverflowError user/S/fn--844/fn--845 (NO_SOURCE_FILE:1)
  23. ((Y fac) 0)
  24.  
  25. ;; StackOverflowError user/S/fn--844/fn--845 (NO_SOURCE_FILE:1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement