108
108
Unquote (` , ` ) also has a cousin called unquote-splicing ` ,@ ` which can insert
109
109
an array of stuff all at once.
110
110
111
- For example, if you want to create a shorthand ` mean ` for calculating the mean
112
- of some numbers , you could do
111
+ For example, if you want to create a shorthand ` mean ` for creating the
112
+ expression necessary to calculate the mean of some variables , you could do
113
113
114
114
<!-- !test in mean macro -->
115
115
@@ -128,18 +128,18 @@ of some numbers, you could do
128
128
; Return a division of the sum of the arguments by the total
129
129
(return `(/ (+ ,@args) ,total))))
130
130
131
- (mean 1 2 3 )
131
+ (mean 1 2 a )
132
132
133
- which effectively creates the eslisp code ` (/ (+ 1 2 3 ) 3) ` that compiles to JS
133
+ which effectively creates the eslisp code ` (/ (+ 1 2 a ) 3) ` that compiles to JS
134
134
as—
135
135
136
136
<!-- !test out mean macro -->
137
137
138
- (1 + (2 + 3 )) / 3;
138
+ (1 + (2 + a )) / 3;
139
139
140
140
If we had used the plain unquote (` , ` ) instead of unquote-splicing (` ,@ ` ), we'd
141
- have gotten ` (/ (+ (1 2 3 )) 3) ` which would compile to nonsense JS, as eslisp
142
- would think ` (1 2 3 ) ` was a function call when ` 1 ` isn't a function.
141
+ have gotten ` (/ (+ (1 2 a )) 3) ` which would compile to nonsense JS, as eslisp
142
+ would think ` (1 2 a ) ` was a function call when ` 1 ` isn't a function.
143
143
144
144
If you don't want to use ` quasiquote ` /`` ` `` & co., and think it's clearer for
145
145
your use-case to just work with objects, you can still always do that.
0 commit comments