Skip to content

Instantly share code, notes, and snippets.

@yokolet
Created March 30, 2014 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokolet/9867528 to your computer and use it in GitHub Desktop.
Save yokolet/9867528 to your computer and use it in GitHub Desktop.
another trampoline example for ClojureBridge CommunityDocs
(defn right-and-left [size]
(letfn
[(go-right [x [start end]]
(cond
(< (inc x) end) (do #_(println "right") (go-right (inc x) [start end]))
(> (dec x) start) (go-left x [start (dec end)])
:else (println "done")))
(go-left [x [start end]]
(cond
(> (dec x) start) (do #_(println "left") (go-left (dec x) [start end]))
(< (inc x) end) (go-right x [(inc start) end])
:else (println "done")))]
(go-right 0 [0 size])))
(defn right-and-left2 [size]
(letfn
[(go-right [x [start end]]
#(cond
(< (inc x) end) (do #_(println "right") (go-right (inc x) [start end]))
(> (dec x) start) (go-left x [start (dec end)])
:else (println "done")))
(go-left [x [start end]]
#(cond
(> (dec x) start) (do #_(println "left") (go-left (dec x) [start end]))
(< (inc x) end) (go-right x [(inc start) end])
:else (println "done")))]
(trampoline go-right 0 [0 size])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment