clojure.spec examples.
-
build tool Leiningen
- Mac OS X:
brew install leiningen
- Mac OS X:
-
alternative:
clj
command- Mac OS X:
brew install clojure
- Mac OS X:
- with Leiningen
$ lein repl
- with
clj
command
$ clj -R:dev -C:dev
This will start Clojure REPL with the following code already executed:
(require '[clojure.spec.alpha :as s]
'[clojure.spec.gen.alpha :as gen]
'[clojure.spec.test.alpha :as stest])
- with Leiningen
$ lein run -m spec-examples.core
- with
clj
command
$ clj -m spec-examples.core
Play Blackjack
In Clojure REPL,
user=> (require '[spec-examples.blackjack.play :as bj])
nil
user=> (bj/init)
dealer: [[9 :spade] ???]
player: [[4 :diamond] [:ace :diamond]] => 15
nil
user=> (bj/hit)
dealer: [[9 :spade] ???]
player: [[3 :club] [4 :diamond] [:ace :diamond]] => 18
nil
user=> (bj/stand)
dealer: [[9 :spade] [8 :diamond]] => 17
player: [[3 :club] [4 :diamond] [:ace :diamond]] => 18
You win!! x1
nil
spec-examples.blackjack/init
: initialise the gamespec-examples.blackjack/hit-by-player
: hit operation by playerspec-examples.blackjack/stand-by-player
: stand operation by player