You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/documentation/global-and-local-bindings.md
+36-26
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,42 @@ Creates a new lexical context with assignments defined in bindings. Afterwards t
40
40
```
41
41
All assignments defined in _bindings_ are immutable and cannot be changed.
42
42
43
+
## Binding
44
+
45
+
While `let` creates a new lexical context, `binding` temporarily redefines existing definitions while executing the body. This can be useful when writing tests on functions depending on external state as `binding` allows to remap existing functions or values with mocks.
46
+
47
+
```phel
48
+
(ns my-app\tests\demo
49
+
(:require phel\test :refer [deftest is]))
50
+
51
+
# Function that would return e.g. "x86_64", depending on the environment:
# ✔ greet-test-binding: i386 system user is greeted accordingly
76
+
77
+
```
78
+
43
79
## Variables
44
80
45
81
```phel
@@ -69,29 +105,3 @@ To update a variable with a function the `swap!` function can be used.
69
105
(swap! foo + 2) # Evaluates to 12
70
106
(deref foo) # Evaluates to 12
71
107
```
72
-
73
-
## Binding
74
-
75
-
While writing tests on code depending on external state can be challenging, `binding` function allows to remap existing bindings which can be used for mocking functions or values during tests. As example, code depending on runtime environment:
76
-
77
-
```phel
78
-
(ns my-app\tests\demo
79
-
(:require phel\test :refer [deftest is]))
80
-
81
-
# Function that would return e.g. "x86_64", depending on the environment:
0 commit comments