mirror of
https://github.com/jbranchaud/til
synced 2026-01-08 01:28:02 +00:00
Add Expanding Macros as a clojure til.
This commit is contained in:
@@ -9,6 +9,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
|
|
||||||
### clojure
|
### clojure
|
||||||
|
|
||||||
|
- [Expanding Macros](clojure/expanding-macros.md)
|
||||||
- [Quick Clojure Docs](clojure/quick-clojure-docs.md)
|
- [Quick Clojure Docs](clojure/quick-clojure-docs.md)
|
||||||
- [Specify the Directory of a Shell Command](clojure/specify-the-directory-of-a-shell-command.md)
|
- [Specify the Directory of a Shell Command](clojure/specify-the-directory-of-a-shell-command.md)
|
||||||
- [Splitting On Whitespace](clojure/splitting-on-whitespace.md)
|
- [Splitting On Whitespace](clojure/splitting-on-whitespace.md)
|
||||||
|
|||||||
24
clojure/expanding-macros.md
Normal file
24
clojure/expanding-macros.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Expanding Macros
|
||||||
|
|
||||||
|
Macros are an important part of Clojure's syntax. They allow you to write
|
||||||
|
cleaner, terser, more expressive code.
|
||||||
|
Though sometimes you may want to inspect the
|
||||||
|
clojure code that is actually produced by a particular macro. The
|
||||||
|
`macroexpand` function allows for just this.
|
||||||
|
|
||||||
|
For instance, if you have a snippet of code using the `->>` operator:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
(->> 4 (+ 1) (- 2) (* 3))
|
||||||
|
```
|
||||||
|
|
||||||
|
You can wrap that form with the `macroexpand` function to see the form that
|
||||||
|
is ultimately evaluated:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
> (macroexpand (->> 4 (+ 1) (- 2) (* 3)))
|
||||||
|
; (* 3 (- 2 (+ 1 4)))
|
||||||
|
```
|
||||||
|
|
||||||
|
It doesn't buy us much in a contrived example like this, but can prove
|
||||||
|
useful for better understanding clojure and the more complex code we write.
|
||||||
Reference in New Issue
Block a user