Skip to content
Newer
Older
100644 218 lines (160 sloc) 4.25 KB
7c720fe @cemerick dump of REPL interactions and other inline code snippets
cemerick authored
1 ;-----
2 *ns*
3 ;= #<Namespace user>
4 (defn a [] 42)
5 ;= #'user/a
6
7
8 ;-----
9 (in-ns 'physics.constants)
10 ;= #<Namespace physics.constants>
11 (def ^:const planck 6.62606957e-34)
12 ;= #'physics.constants/planck
13
14
15 ;-----
16 (+ 1 1)
17 ;= #<CompilerException java.lang.RuntimeException:
18 ;= Unable to resolve symbol: + in this context, compiling:(NO_SOURCE_PATH:1)>
19
20
21 ;-----
22 (clojure.core/range -20 20 4)
23 ;= (-20 -16 -12 -8 -4 0 4 8 12 16)
24
25
26 ;-----
27 user/a
28 ;= #<user$a user$a@6080669d>
29 (clojure.core/refer 'user)
30 ;= nil
31 (a)
32 ;= 42
33
34
35 ;-----
36 (clojure.core/refer 'clojure.core
37 :exclude '(range)
38 :rename '{+ add
39 - sub
40 / div
41 * mul})
42 ;= nil
43 (-> 5 (add 18) (mul 2) (sub 6))
44 ;= 40
45 (range -20 20 4)
46 ;= #<CompilerException java.lang.RuntimeException:
47 ;= Unable to resolve symbol: range in this context, compiling:(NO_SOURCE_PATH:1)>
48
49
50 ;-----
51 (clojure.set/union #{1 2 3} #{4 5 6})
52 ;= #<ClassNotFoundException java.lang.ClassNotFoundException: clojure.set>
53
54
55 ;-----
56 (require 'clojure.set)
57 ;= nil
58 (clojure.set/union #{1 2 3} #{4 5 6})
59 ;= #{1 2 3 4 5 6}
60
61
62 ;-----
63 (require '[clojure.set :as set])
64 ;= nil
65 (set/union #{1 2 3} #{4 5 6})
66 ;= #{1 2 3 4 5 6}
67
68
69 ;-----
70 (require '(clojure string [set :as set]))
71
72
73 ;-----
74 (require 'clojure.xml)
75 (refer 'clojure.xml)
76
77
78 ;-----
79 (use '(clojure [string :only (join) :as str]
80 [set :exclude (join)]))
81 ;= nil
82 join
83 ;= #<string$join clojure.string$join@2259a735>
84 intersection
85 ;= #<set$intersection clojure.set$intersection@2f7fc44f>
86 str/trim
87 ;= #<string$trim clojure.string$trim@283aa791>
88
89
90 ;-----
91 (require '(clojure [string :as str]
92 [set :as set]))
93
94
95 ;-----
96 (use '[clojure.set :as set :only (intersection)])
97
98
99 ;-----
100 (Date.)
101 ;= #<CompilerException java.lang.IllegalArgumentException:
102 ;= Unable to resolve classname: Date, compiling:(NO_SOURCE_PATH:1)>
103 (java.util.Date.)
104 ;= #<Date Mon Jul 18 12:31:38 EDT 2011>
105 (import 'java.util.Date 'java.text.SimpleDateFormat)
106 ;= java.text.SimpleDateFormat
107 (.format (SimpleDateFormat. "MM/dd/yyyy") (Date.))
108 ;= "07/18/2011"
109
110
111 ;-----
112 (import '(java.util Arrays Collections))
113 ;= java.util.Collections
114 (->> (iterate inc 0)
115 (take 5)
116 into-array
117 Arrays/asList
118 Collections/max)
119 ;= 4
120
121
122 ;-----
123 (import 'java.awt.List 'java.util.List)
124 ;= #<IllegalStateException java.lang.IllegalStateException:
125 ;= List already refers to: class java.awt.List in namespace: user>
126
127
128 ;-----
129 (in-ns 'examples.ns)
130 (clojure.core/refer 'clojure.core :exclude '[next replace remove])
131 (require '(clojure [string :as string]
132 [set :as set])
133 '[clojure.java.shell :as sh])
134 (use '(clojure zip xml))
135 (import 'java.util.Date
136 'java.text.SimpleDateFormat
137 '(java.util.concurrent Executors
138 LinkedBlockingQueue))
139
140
141 ;-----
142 (ns examples.ns
143 (:refer-clojure :exclude [next replace remove])
144 (:require (clojure [string :as string]
145 [set :as set])
146 [clojure.java.shell :as sh])
147 (:use (clojure zip xml))
148 (:import java.util.Date
149 java.text.SimpleDateFormat
150 (java.util.concurrent Executors
151 LinkedBlockingQueue)))
152
153
154 ;-----
155 #<Exception java.lang.Exception:
156 Cyclic load dependency:
157 [ /some/namespace/X ]->/some/namespace/Y->[ /some/namespace/X ]>
158
159
160 ;-----
161 (defn a [x] (+ constant (b x)))
162 ;= #<CompilerException java.lang.RuntimeException:
163 ;= Unable to resolve symbol: constant in this context, compiling:(NO_SOURCE_PATH:1)>
164
165
166 ;-----
167 (declare constant b)
168 ;= #'user/b
169 (defn a [x] (+ constant (b x)))
170 ;= #'user/a
171 (def constant 42)
172 ;= #'user/constant
173 (defn b [y] (max y constant))
174 ;= #'user/b
175 (a 100)
176 ;= 142
177
178
179 ;-----
180 java -cp '.:src:clojure.jar:lib/*' clojure.main
181
182
183 ;-----
184 '.;src;clojure.jar;lib\*'
185
186
187 ;-----
188 $ java -cp clojure.jar clojure.main
189 Clojure 1.3.0
190 (System/getProperty "java.class.path")
191 ;= "clojure.jar"
192
193
194 ;-----
195 [org.clojure/clojure "1.3.0"]
196
197
198 ;-----
199 <dependency>
200 <groupId>org.clojure</groupId>
201 <artifactId>clojure</artifactId>
202 <version>1.3.0</version>
203 </dependency>
204
205 ;-----
206 (defproject com.clojurebook/lein-mixed-source "1.0.0"
207 :dependencies [[org.clojure/clojure "1.3.0"]]
208 :aot :all)
209
210 (require '(leiningen compile javac))
211
212 (add-hook #'leiningen.compile/compile
213 (fn [compile project & args]
214 (apply compile project args)
215 (leiningen.javac/javac (assoc project :java-source-path "srcj"))))
216
217
Something went wrong with that request. Please try again.