clojure.spec examples
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
env/dev/clj
specs/clj/spec_examples
src
test/clj/spec_examples
.gitignore
CHANGELOG.md
LICENSE
README.md
deps.edn
project.clj

README.md

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

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

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