Last active
January 20, 2019 05:18
-
-
Save viebel/a088ac5acd7d03486d50e7062b7a0a4d to your computer and use it in GitHub Desktop.
Clojure quick start http://app.klipse.tech/?eval_only=1&cljs_in.gist=viebel/a088ac5acd7d03486d50e7062b7a0a4d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def summaries ["cold" "moderate"]) ;; creates a vector with two strings: "cold" and "moderate" | |
(def new-summaries (assoc summaries 2 "hot")) ;; creates a new vector with an additional string: "hot" | |
(def old-names {:c "celsius" }) ;; creates a map from keywords to strings | |
(def names (assoc old-names {:f "farenheit"})) ;; creates a new map with additional entry | |
(defn celsius->farenheit [c] ;; define a function that converts from celsius to farenheit | |
(+ 32 (* c 9/5))) ;; c * 9/5 + 32 | |
(defn celsius->summary [c] ;; define a function that converts from celsius to summary | |
(if (and (>= c 6) ;; when c is between 6 and 25, it's moderate | |
(< c 25)) | |
(nth new-summaries 1) | |
(if (>= c 25) | |
(nth new-summaries 2) ;; when c is above 25, it's hot | |
(nth new-summaries 0)))) ;; otherwise it's cold | |
(defn sentences [] ;; define the sentences function | |
(for [c (range -8 43) ;; go over all the numbers between -8 (included) and 43 (excluded) | |
:when (even? c)] ;; keep only the even numbers | |
(let [f (celsius->farenheit c) ;; create local bindings with f and summary | |
summary (celsius->summary c)] | |
(str c " " (:c names) ;; creates a string with the celsius, the farenheit and the summary | |
" is " f " " (:f names) | |
", " summary)))) | |
(sentences) ;; call the sentences function | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment