Skip to content

Instantly share code, notes, and snippets.

@jasonjckn
Created June 5, 2011 01:15
Show Gist options
  • Save jasonjckn/1008549 to your computer and use it in GitHub Desktop.
Save jasonjckn/1008549 to your computer and use it in GitHub Desktop.
(defn Y [f]
(f f))
((Y (fn [coll]
(if-let [[a0 & as] (seq coll)]
(+ a0 ((h h) as))
0)))
[1 2 3 4 5])
@jasonjckn
Copy link
Author

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))

@amalloy
Copy link

amalloy commented Jun 5, 2011

Yeah, you're right about as. Silly me.

@jasonjckn
Copy link
Author

try to paste this code again:

(defn sum-gen [h]
  (fn [[a0 & as :as a]]
    (if (seq a)
      (+ a0 ((h h) as))
      0)))

@jasonjckn
Copy link
Author

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)

@amalloy
Copy link

amalloy commented Jun 5, 2011

(fn [coll]
  (if-let [[a & as] (seq coll)]
    ...))

@jasonjckn
Copy link
Author

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment