Created
February 19, 2011 02:22
-
-
Save masaedw/834767 to your computer and use it in GitHub Desktop.
This file contains 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
;;; 変数に設定 | |
;; 整数を受け取って | |
;; 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 |
This file contains 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
(if (= a 0) | |
b | |
c) |
This file contains 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
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