A workshop for writing macros.
It covers the basic elements of a macro and shows you the difference and similarity between puzzling things like `'~....
Here it goes
https://gist.github.com/anonymous/49053496eb88c7c6a1a1
Sunday, May 18, 2014
Wednesday, March 19, 2014
var and symbol
A symbol object stands for the symbol itself, not the value.
Example:
'abc
(symbol "abc")
These guys are the same thing. They are a symbol object.
In runtime, you can evaluate a symbol to find out the value associated with them.
;;; suppose you had a variable named "abc"
; (def abc 20)
(eval 'abc)
(eval (symbol "abc")) ;; ==> 20
A var is an object holding the value of a symbol.
(def ^:dynamic a 3)
(binding [a 30]
(var-set (var a) 300)
(println a)
(var-set (resolve (symbol "a")) 3000)
(println a)
(var-set #'a 30000)
(println a)
(set! a 30000) (println a)
)
1. In compile time (var a) is resolved to the var object itself.
2. In runtime, (resolve 'a) or (resolve (symbol "a")) is something stands for the var object itself.
// #'xxx is a macro, expands to (var xxx)
Example:
'abc
(symbol "abc")
These guys are the same thing. They are a symbol object.
In runtime, you can evaluate a symbol to find out the value associated with them.
;;; suppose you had a variable named "abc"
; (def abc 20)
(eval 'abc)
(eval (symbol "abc")) ;; ==> 20
A var is an object holding the value of a symbol.
(def ^:dynamic a 3)
(binding [a 30]
(var-set (var a) 300)
(println a)
(var-set (resolve (symbol "a")) 3000)
(println a)
(var-set #'a 30000)
(println a)
(set! a 30000) (println a)
)
1. In compile time (var a) is resolved to the var object itself.
2. In runtime, (resolve 'a) or (resolve (symbol "a")) is something stands for the var object itself.
// #'xxx is a macro, expands to (var xxx)
Saturday, February 15, 2014
Using expectations
1. Install expectations lib
Goto http://jayfields.com/expectations/installing.html
Or, simple add [expectations "1.4.52"] into your project.clj
2. Install expectations plugin for leiningen
add :plugins [[lein-expectations "0.0.7"]] into your project.clj
3. Write your tests
(expect nil? nil)
(expect (add 2 3) 5)
4. Run your tests
lein expectations
5. Install autoexpect (to Automate it)
Goto https://github.com/jakemcc/lein-autoexpect
or add [lein-autoexpect "1.0"] to plugins section of project.clj
6. Run autoexpect
lein autoexpect
Goto http://jayfields.com/expectations/installing.html
Or, simple add [expectations "1.4.52"] into your project.clj
2. Install expectations plugin for leiningen
add :plugins [[lein-expectations "0.0.7"]] into your project.clj
3. Write your tests
(expect nil? nil)
(expect (add 2 3) 5)
4. Run your tests
lein expectations
5. Install autoexpect (to Automate it)
Goto https://github.com/jakemcc/lein-autoexpect
or add [lein-autoexpect "1.0"] to plugins section of project.clj
6. Run autoexpect
lein autoexpect
Subscribe to:
Comments (Atom)