Reading — step 1 of 5
Learn
~1 min readLisp Basics
Two ways to bind values to names:
def — top-level (global) binding:
(def pi 3.14159)
(def greeting "Hello")
let — local, lexically-scoped binding:
(let [x 10
y 20]
(+ x y)) ; 30
let takes a vector of [name value name value ...] and a body. The bindings are visible only inside the body.
Clojure has these atomic types:
- numbers:
42,3.14,1/3(ratio!) - strings:
"hello" - characters:
\a,\space - keywords:
:name,:age— like enum tags, used heavily as map keys - symbols: bare names like
pi,greeting - nil:
nil(also represents false in conditionals) - booleans:
true,false
Reading stdin: (read-line) reads one line. Convert with Integer/parseInt, Double/parseDouble (interop with Java).
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…