Skip to content

lagenorhynque/spec-examples

Repository files navigation

spec-examples

CircleCI

clojure.spec examples.

Prerequisites

  • build tool Leiningen

    • Mac OS X: brew install leiningen
  • alternative: clj command

    • Mac OS X: brew install clojure

Experiment with REPL

  • 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])

Run example code

  • with Leiningen
$ lein run -m spec-examples.core
  • with clj command
$ clj -m spec-examples.core

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

available commands

  • spec-examples.blackjack/init: initialise the game
  • spec-examples.blackjack/hit-by-player: hit operation by player
  • spec-examples.blackjack/stand-by-player: stand operation by player