Make a simple function called greet that returns the most-famous "hello world!".
寫回傳字串 "hello world!"
的函式
;; testing
(ns hello-world-test
(:require [clojure.test :refer :all]
[hello-world :refer [greet]]))
(deftest hello-world
(testing "Is it a function?"
(is (function? greet) "greet should be a function"))
(testing "Does it return the correct value?"
(is (= (greet) "hello world!") "greet should return \"hello world!\""))
)
(ns hello-world)
(defn greet []
(str "hello world!"))
函式特性:
defn
定義有名字的函式,上述函式名稱為 greetvector, []
中,可以多個參數list, ()
的第一個位置可以呼叫函式