Compare commits
1 Commits
6e228128a4
...
b2e670c29b
Author | SHA1 | Date |
---|---|---|
|
b2e670c29b |
|
@ -1,62 +1,5 @@
|
|||
#+TITLE: Getting started with Clojure some of the basics.
|
||||
|
||||
* Clojure datatype's
|
||||
Clojure is a very dynamic and interactive language it is able to give very in depth feed back of your running program, all code below can evaluated live inside an IDE when connected.
|
||||
|
||||
Basic data
|
||||
#+BEGIN_SRC clojure :tangle src/core.cljc
|
||||
;; comments are semi colon, linters will treat alignment different bassed on the number of semi colons
|
||||
;;Integers
|
||||
1234
|
||||
;;Doubles
|
||||
1.234
|
||||
;;BigDecimal
|
||||
2.33M
|
||||
;;Ratios are allowed
|
||||
34/3
|
||||
;;Strings are double quoted
|
||||
"Hello World"
|
||||
;;characters are backslash escaped
|
||||
\a \b \c \e \t \c
|
||||
;;Symbols (named things like function & variable) are just text
|
||||
my-var-name my-fn-name my-second-var-etc my-second-fn-etc
|
||||
;;hash map or dictonary keys are prefixed with a colon, no need to quote
|
||||
:key1 :key2 :key3
|
||||
;;booleans
|
||||
true false
|
||||
;; Null or None is just nil
|
||||
nil
|
||||
;; Regex patterns are strings prefixed with a hash symbol
|
||||
#"^Begins with this text"
|
||||
#+END_SRC
|
||||
|
||||
Collections of data
|
||||
#+BEGIN_SRC clojure :tangle src/core.cljc
|
||||
;; List are wrapped in brackets, space or comma act as seerators
|
||||
(1 2 3 4 5 6 7 8 9)
|
||||
;; Lists are special in that they need to be escaped to be treated as data
|
||||
;; using the list function or the quote symbol, which is short hand and explained later.
|
||||
(list 1 2 3 4 5 6 7 8 9)
|
||||
'(1 2 3 4 5 6 7 8 9)
|
||||
|
||||
;;Vectors or indexed lists are created with square brackets
|
||||
;;or using the long form vector function
|
||||
[1 2 3 4 5 6 7 8 9]
|
||||
(vector 1 2 3 4 5 6 7 8 9)
|
||||
|
||||
;; hash-maps are denoted with curly braces or calling hash-map function
|
||||
;; they must always contain key value pairs.
|
||||
{:key-one 1 :key-two 2}
|
||||
(hash-map :key-one 1 :key-two 2)
|
||||
|
||||
;; sets also use curly braces but start with a # or you can call hash-set function
|
||||
;; sets have to be unique so duplicates will throw an error
|
||||
#{1 2 3}
|
||||
(hash-set 1 2 3)
|
||||
;;#{1 2 1 3} how ever would through an error, using hash-set would remove the duplicate with out error.
|
||||
#+END_SRC
|
||||
|
||||
|
||||
* Language syntax
|
||||
The clojure syntax is super simple it is always a function call followed by arguments, this applies for things like standard conditionals and, or, not etc
|
||||
|
||||
|
|
Loading…
Reference in New Issue