This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-24
Channels
- # announcements (8)
- # aws (12)
- # babashka (84)
- # beginners (380)
- # calva (56)
- # clj-kondo (52)
- # cljdoc (4)
- # cljs-dev (327)
- # cljsrn (4)
- # clojure (154)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-uk (21)
- # clojurescript (52)
- # conjure (133)
- # cursive (64)
- # datomic (33)
- # emacs (22)
- # fulcro (35)
- # graalvm (24)
- # graphql (1)
- # kaocha (1)
- # leiningen (1)
- # off-topic (24)
- # onyx (2)
- # pathom (10)
- # re-frame (3)
- # reagent (3)
- # reitit (3)
- # shadow-cljs (48)
- # spacemacs (12)
- # tools-deps (98)
- # xtdb (7)
måning!
So, today, continuing on with my little introduction to some other colleagues at work (non-programmers) on Clojure
today I'l be introducing if and cond and looping by way of a simple guessing game (computer chooses a random number, and you get to type a number in and it tells you if it's higher or lower, until you guess right!)
looping as in loop
/`recur` @dharrigan?
is that because loop
/`recur` make for conceptually easy console-based input cycles ?
(defn guessing-game
[]
(let [my-number (rand-int 100)]
(loop [guess (read-number)]
(if (= guess my-number)
(println "Well Done! Yes, the number I was thinking of was:" my-number)
(do
(cond
(> guess my-number) (println "My number is lower!")
(< guess my-number) (println "My number is higher!"))
(recur (read-number)))))))
yeah, i was just curious, 'cos i actively avoid loop
/`recur` most of the time, but for simple prompt stuff it is conceptually very straightforward