Skip to content

Instantly share code, notes, and snippets.

@masaedw
Created February 19, 2011 02:22
Show Gist options
  • Save masaedw/834767 to your computer and use it in GitHub Desktop.
Save masaedw/834767 to your computer and use it in GitHub Desktop.
;;; 変数に設定
;; 整数を受け取って
;; 10を足して返す関数
(defn plus10 [a]
(+ a 10))
(def f plus10)
;; 42
(def i (f 32))
;;; 引数に渡す
(defn mul2 [n]
(* n 2))
;; 整数を取る関数fを受け取って、
;; その関数に10を適用する関数
(defn apply10 [f]
(f 10))
(println (apply10 mul2))
;;; 戻り値として受け取る
(defn plusN [n]
(fn [x] (+ x n)))
(println ((plusN 5) 2)) ; 7
(def plus5 (plusN 5))
(println (plus5 2)) ; 7
(if (= a 0)
b
c)
if (a == 0)
return b;
return c;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment