-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.clj
36 lines (28 loc) · 868 Bytes
/
util.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns moarquil.util
"
Utilities namespace.
"
(:require [quil.core :refer :all]))
(defmacro defcontext
"
Create a contextual macro[1] with setup and teardown. The teardown
executes even if the body raises an exception.
[1] Macro-writing-macros hurt my brain. This helps:
`http://hubpages.com/technology/Clojure-macro-writing-macros`.
See also:
`http://eigenhombre.com/macro-writing-macros.html`
"
[nom setup teardown]
`(defmacro ~(symbol (str "with-" nom))
[~'& body#]
`(do
~'~setup
(try
~@body#
(finally
~'~teardown)))))
;; The actual context macros, with specified setup and teardown steps.
;; Example usage: `(with-style ...body... )`.
(defcontext style (push-style) (pop-style))
(defcontext shape (begin-shape) (end-shape))
(defcontext matrix (push-matrix) (pop-matrix))