Skip to content

Instantly share code, notes, and snippets.

@sdtsui
Created January 22, 2016 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdtsui/4026a4df7f4e08cff78c to your computer and use it in GitHub Desktop.
Save sdtsui/4026a4df7f4e08cff78c to your computer and use it in GitHub Desktop.
ex1
;Working ClojureScript
(defn rps [p1 p2]
(if (== (count p1) (count p2)) "Draw!"
(let [win1 "Player 1 won!" win2 "Player 2 won!"]
(if (== p1 "scissors") (if (== p2 "paper") win1 win2)
(if (== p1 "rock") (if (== p2 "scissors") win1 win2)
(if (== p1 "paper") (if (== p2 "rock") win1 win2)
nil
)
)
)
)
)
)
;throws:
;java.lang.ClassCastException:
;java.lang.String cannot be cast to java.lang.Number at
;clojure.lang.Numbers.equiv (Numbers.java:206)
;in web repl (not in codewars env):
;java.lang.IllegalStateException: Attempting to call unbound fn:
(def rps
(fn [p1 p2]
(if (== (count p1) (count p2)) "Draw!"
(let [win1 "Player 1 won!" win2 "Player 2 won!"]
(if (== p1 "scissors") (if (== p2 "paper") win1 win2)
(if (== p1 "rock") (if (== p2 "scissors") win1 win2)
(if (== p1 "paper") (if (== p2 "rock") win1 win2)
nil
)
)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment