Skip to content

Commit bdc02b7

Browse files
committed
Clarify that qq example can take variables
Why this macro is an example here to begin with is that it works for any inputs, not only numbers. This clarifies that.
1 parent e567184 commit bdc02b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

doc/how-macros-work.markdown

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ like
108108
Unquote (`,`) also has a cousin called unquote-splicing `,@` which can insert
109109
an array of stuff all at once.
110110

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
113113

114114
<!-- !test in mean macro -->
115115

@@ -128,18 +128,18 @@ of some numbers, you could do
128128
; Return a division of the sum of the arguments by the total
129129
(return `(/ (+ ,@args) ,total))))
130130

131-
(mean 1 2 3)
131+
(mean 1 2 a)
132132

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
134134
as—
135135

136136
<!-- !test out mean macro -->
137137

138-
(1 + (2 + 3)) / 3;
138+
(1 + (2 + a)) / 3;
139139

140140
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.
143143

144144
If you don't want to use `quasiquote`/`` ` `` & co., and think it's clearer for
145145
your use-case to just work with objects, you can still always do that.

0 commit comments

Comments
 (0)