Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 112 lines (61 sloc) 1.411 kb
38152c9 @russolsen Added examples, readme file.
authored
1 ; Data types: java strings
2
3 "abc"
4
5 ; (java ) chars
6
7 \a
8 \b
9 \c
10
11 ; Numbers
12
13 123
14 3.14159
15
16 ; Big numbers long/BigInteger
17
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
18 (* 99999999 (BigInteger. "999999999999999"))
38152c9 @russolsen Added examples, readme file.
authored
19
20 ; Symbols refer to things
21
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
22 (def y 99)
38152c9 @russolsen Added examples, readme file.
authored
23
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
24 y ; is a symbol, refers to 99
38152c9 @russolsen Added examples, readme file.
authored
25 max ; is a function
26 + ; so is +
27 java.lang.String
28
29
30 ; Keywords refer to themselves
31
32 :first_name
33 :last_name
34 :import
35
36
37 ; A list is a first/rest pair
38
39 '( a b c (d e (f g) h i ) j )
40
41
42 ; Bind it to a name
43
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
44 (def x '( a b c (d e (f g) h i ) j ))
38152c9 @russolsen Added examples, readme file.
authored
45
46 ; Get the first item of the list
47
48 (first x)
49
50 ; Get everything but the first
51
52 (rest x )
53
54 ; concatenate it to another list
55
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
56 (concat x '( 1 2 3 ))
38152c9 @russolsen Added examples, readme file.
authored
57
58 ; Add an element to the front
59
60 (cons 1 x)
61
62
63 ; A vector is more or less an array list
64
65 [ 1 2 3 ]
66
67 (first [1 2 3])
68 (rest [1 2 3])
69
70 ; A hash maps names->values
71
72 { :fname "russ" :lname "Olsen"}
73
74 (def h { :fname "russ" :lname "Olsen"} )
75
76 (:fname h)
77
78 (assoc h :age 10 )
79
80
81
82 ; The critical thing about LISP and clojure is
83 ; that the code and the data are the same thing:
84
85 (def p '(println "Hello from this bit of clojure"))
86
87 (eval p)
88
89 (def p '(defn say-hello [] (println "hello out there")))
90
91 (eval p)
92
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
93 ; Evaluating clojure code
38152c9 @russolsen Added examples, readme file.
authored
94 ; Many things evaluate to themselves
95
96 1
97 :foo
98 "hello"
99 p
100 concat
101
102 ; Feed clojure a list and it will take the first
02665a0 @trptcolin Update examples to work on 1.3 as well
trptcolin authored
103 ; item of the list as a function and try to
38152c9 @russolsen Added examples, readme file.
authored
104 ; evaluate the function using the rest as
105 ; arguments
106
107 (foo 1 2 3) ; no function
108
109 (max 1 2 3) ; yes!
110
111
Something went wrong with that request. Please try again.