Created
June 5, 2011 01:15
-
-
Save jasonjckn/1008549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn Y [f] | |
(f f)) | |
((Y (fn [coll] | |
(if-let [[a0 & as] (seq coll)] | |
(+ a0 ((h h) as)) | |
0))) | |
[1 2 3 4 5]) |
Oh, you're right about (f f), I can't believe I missed that. :)
(if as ..) would terminate too early afaik.
you're right about the issues though, this is better:
(ns ycomb-simpler)
(defn sum-gen [h](fn [[a0 & as :as a]]
%28if %28seq a%29
%28+ a0 %28%28h h%29 as%29%29
0%29))
Yeah, you're right about as. Silly me.
try to paste this code again:
(defn sum-gen [h] (fn [[a0 & as :as a]] (if (seq a) (+ a0 ((h h) as)) 0)))
Anyways, now the ycombinator is laughably simple.
The more complex version is just to get prettier anonymous function declarations, such as:
(defn sum-gen [h] (fn [[a0 & as :as a]] (if (seq a) (+ a0 (h as)) 0)))
instead of (h h)
(fn [coll]
(if-let [[a & as] (seq coll)]
...))
Perfect!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should probably be
(if as)
, no? Won't matter for ints, but is a more general pattern for if the coll can have nil/false elements.And isn't
((fn [h] (h h)) f)
identical to(f f)
?