lagenorhynque / spec-examples

clojure.spec examples

Home Page:https://www.slideshare.net/KentOhashi/spectacular-future-with-clojurespec

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

clojure.spec examples

https://www.slideshare.net/KentOhashi/spectacular-future-with-clojurespec

License:Eclipse Public License 1.0


Languages

Language:Clojure 86.9%Language:Java 13.1%