Skip to content

Instantly share code, notes, and snippets.

@viebel viebel/quick-start.clj
Last active Jan 20, 2019

What would you like to do?
(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
You can’t perform that action at this time.