Skip to content

Instantly share code, notes, and snippets.

View yokolet's full-sized avatar
🏠
Doing Rails dev now

Yoko Harada yokolet

🏠
Doing Rails dev now
View GitHub Profile
@yokolet
yokolet / do_something.clj
Created February 22, 2014 20:04
sample function for multiple arities
(defn do-something
([] "nothing")
([one] "easy!")
([one two] "hm, ok, will do")
([one two & more] "oh, no, so many!"))
@yokolet
yokolet / add-up.clj
Created February 22, 2014 21:09
function example for ClojureBridge CommunityDocs
(defn add-up
"takes initial value and collection,
returns sum of value and collection's all element"
([val coll]
(let [_ (println (str "val: " val ", coll: " coll))]
(cond
(empty? coll) val
:else (add-up (+ val (first coll)) (rest coll))))))
@yokolet
yokolet / hello-world-with-block-comment.clj
Last active August 29, 2015 13:56
Block comment example for ClojureBridge CommunityDocs
(comment
;; The first version of main function.
;; TODO delete if a new version completes.
(defn -main []
"I can say 'Hello World'."
(println "Hello, World!"))
)
(defn hello-world [] (println "Hello, World!"))
@yokolet
yokolet / project.clj
Created March 5, 2014 00:44
hello-hiccup project - ClojureBridge CommunityDocs
(defproject hello-hiccup "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[hiccup "1.0.5"]])
@yokolet
yokolet / core.clj
Created March 5, 2014 01:05
src/hello-hiccup/core.clj - ClojureBridge CommunityDocs
(ns hello-hiccup.core
(:use [hiccup.core]))
@yokolet
yokolet / recursive-call.clj
Created March 30, 2014 01:50
Recursive call functions which raise java.lang.StackOverflowError
(declare incrementor decrementor)
(defn incrementor [n]
(let [_ (print (str n ", "))
next-val (+ n (rand-int 100))]
(if (< -10000 next-val)
(decrementor next-val))))
(defn decrementor [n]
(let [_ (print (str n ", "))
@yokolet
yokolet / trampoline-able-call.clj
Created March 30, 2014 02:10
Recursive call functions used from trampoline - for ClojureBridge CommunityDocs
(declare incrementor2 decrementor2)
(defn incrementor2 [n]
(let [_ (print (str n ", "))
next-val (+ n (rand-int 100))]
(if (< -10000 next-val)
#(decrementor2 next-val))))
(defn decrementor2 [n]
(let [_ (print (str n ", "))
@yokolet
yokolet / right-and-left.clj
Created March 30, 2014 04:26
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]))
@yokolet
yokolet / question.clj
Last active August 29, 2015 13:58
sample of function with let for ClojureBridge CommunityDocs
(defn question [she he]
(let [hers (str she "'s")
his (str he "'s")]
(str "Hey " she ", are " hers " and " his " the same?")))
@yokolet
yokolet / right-triangle-test.clj
Last active August 29, 2015 13:58
sample of function with let for ClojureBridge CommunityDocs
(defn right-triangle? [coll]
(let [a-square (* (nth coll 0) (nth coll 0))
b-square (* (nth coll 1) (nth coll 1))
c-square (* (nth coll 2) (nth coll 2))]
(= (+ a-square b-square) c-square)))
(right-triangle? [1 2 3])