I am writing a simple DiceRoller application and I created the main function, however, I am wondering if there is a βsmartβ way to check function inputs in Clojure instead of using conditional branch expressions to validate input? My function is below with a sample test, I will also need to check if n is not a number with another, if or or, and it feels dirty.
Also, if someone could point out a smarter way to execute this function, I would appreciate any feedback, this is my first attempt to try to functionally program
(ns DiceRoller) (defn roll "rolls a specified number of n sided dice " ([] (roll 1 6)) ([number] (roll number 6)) ([number n] (if-not number? number (throw (IllegalArgumentException. (str "incorrect input, integers only")))) (take number (repeatedly
SMC
source share