-
Notifications
You must be signed in to change notification settings - Fork 1
/
scope.cljc
68 lines (48 loc) · 1.71 KB
/
scope.cljc
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(ns fif.stack-machine.scope
"Stack machine functions for manipulating the scope."
(:require
[fif.stack-machine :as stack]
[fif.utils.scope :as utils.scope]))
(defn get-scope [sm]
(stack/get-scope sm))
(defn set-scope [sm scope]
(stack/set-scope sm scope))
(defn new-scope
"Create a new scope environment within the stack machine."
[sm]
(let [scope (stack/get-scope sm)]
(stack/set-scope sm (utils.scope/new-scope scope))))
(defn clear-scope
[sm]
(stack/set-scope sm (utils.scope/new-scope)))
(defn update-scope
"Update the current scope environment within the stack machine."
[sm f & args]
(let [scope (stack/get-scope sm)]
(stack/set-scope sm (apply utils.scope/update-scope scope f args))))
(defn remove-scope
"Remove the current scope environment from within the stack machine."
[sm]
(let [scope (stack/get-scope sm)]
(stack/set-scope sm (utils.scope/remove-scope scope))))
(defn get-in-scope
"Retrieve within the latest scope, the given nested attribute."
([sm attrs default]
(let [scope (stack/get-scope sm)]
(utils.scope/get-in-scope scope attrs default)))
([scope attrs] (get-in-scope scope attrs nil)))
(defn update-global-scope
"Update the current scope environment within the stack machine."
[sm f & args]
(let [scope (stack/get-scope sm)]
(stack/set-scope sm (apply utils.scope/update-global-scope scope f args))))
(defn get-in-global-scope
"Retrieves from the earliest scope"
([sm attrs default]
(let [fscope (-> sm stack/get-scope first)]
(get-in fscope attrs default)))
([sm attrs] (get-in-global-scope sm attrs nil)))
(defn get-merged-scope
[sm]
(let [scope (stack/get-scope sm)]
(utils.scope/get-merged-scope scope)))