@@ -81,12 +81,8 @@ julia> @macroexpand Base.Cartesian.@nref 3 A i
81
81
:(A[i_1, i_2, i_3])
82
82
```
83
83
"""
84
- macro nref (N, A, sym)
85
- _nref (N, A, sym)
86
- end
87
-
88
- function _nref (N:: Int , A:: Symbol , ex)
89
- vars = [ inlineanonymous (ex,i) for i = 1 : N ]
84
+ macro nref (N:: Int , A:: Symbol , ex)
85
+ vars = Any[ inlineanonymous (ex,i) for i = 1 : N ]
90
86
Expr (:escape , Expr (:ref , A, vars... ))
91
87
end
92
88
@@ -105,14 +101,10 @@ while `@ncall 2 func a b i->c[i]` yields
105
101
func(a, b, c[1], c[2])
106
102
107
103
"""
108
- macro ncall (N, f, sym... )
109
- _ncall (N, f, sym... )
110
- end
111
-
112
- function _ncall (N:: Int , f, args... )
104
+ macro ncall (N:: Int , f, args... )
113
105
pre = args[1 : end - 1 ]
114
106
ex = args[end ]
115
- vars = [ inlineanonymous (ex,i) for i = 1 : N ]
107
+ vars = Any [ inlineanonymous (ex,i) for i = 1 : N ]
116
108
Expr (:escape , Expr (:call , f, pre... , vars... ))
117
109
end
118
110
@@ -132,12 +124,8 @@ quote
132
124
end
133
125
```
134
126
"""
135
- macro nexprs (N, ex)
136
- _nexprs (N, ex)
137
- end
138
-
139
- function _nexprs (N:: Int , ex:: Expr )
140
- exs = [ inlineanonymous (ex,i) for i = 1 : N ]
127
+ macro nexprs (N:: Int , ex:: Expr )
128
+ exs = Any[ inlineanonymous (ex,i) for i = 1 : N ]
141
129
Expr (:escape , Expr (:block , exs... ))
142
130
end
143
131
@@ -159,17 +147,13 @@ while `@nextract 3 x d->y[2d-1]` yields
159
147
x_3 = y[5]
160
148
161
149
"""
162
- macro nextract (N, esym, isym)
163
- _nextract (N, esym, isym)
164
- end
165
-
166
- function _nextract (N:: Int , esym:: Symbol , isym:: Symbol )
167
- aexprs = [Expr (:escape , Expr (:(= ), inlineanonymous (esym, i), :(($ isym)[$ i]))) for i = 1 : N]
150
+ macro nextract (N:: Int , esym:: Symbol , isym:: Symbol )
151
+ aexprs = Any[ Expr (:escape , Expr (:(= ), inlineanonymous (esym, i), :(($ isym)[$ i]))) for i = 1 : N ]
168
152
Expr (:block , aexprs... )
169
153
end
170
154
171
- function _nextract (N:: Int , esym:: Symbol , ex:: Expr )
172
- aexprs = [ Expr (:escape , Expr (:(= ), inlineanonymous (esym, i), inlineanonymous (ex,i))) for i = 1 : N]
155
+ macro nextract (N:: Int , esym:: Symbol , ex:: Expr )
156
+ aexprs = Any[ Expr (:escape , Expr (:(= ), inlineanonymous (esym, i), inlineanonymous (ex,i))) for i = 1 : N ]
173
157
Expr (:block , aexprs... )
174
158
end
175
159
@@ -182,15 +166,11 @@ evaluate to `true`.
182
166
`@nall 3 d->(i_d > 1)` would generate the expression `(i_1 > 1 && i_2 > 1 && i_3 > 1)`. This
183
167
can be convenient for bounds-checking.
184
168
"""
185
- macro nall (N, criterion)
186
- _nall (N, criterion)
187
- end
188
-
189
- function _nall (N:: Int , criterion:: Expr )
169
+ macro nall (N:: Int , criterion:: Expr )
190
170
if criterion. head != :->
191
171
throw (ArgumentError (" second argument must be an anonymous function expression yielding the criterion" ))
192
172
end
193
- conds = [ Expr (:escape , inlineanonymous (criterion, i)) for i = 1 : N]
173
+ conds = Any[ Expr (:escape , inlineanonymous (criterion, i)) for i = 1 : N ]
194
174
Expr (:&& , conds... )
195
175
end
196
176
@@ -202,15 +182,11 @@ evaluate to `true`.
202
182
203
183
`@nany 3 d->(i_d > 1)` would generate the expression `(i_1 > 1 || i_2 > 1 || i_3 > 1)`.
204
184
"""
205
- macro nany (N, criterion)
206
- _nany (N, criterion)
207
- end
208
-
209
- function _nany (N:: Int , criterion:: Expr )
185
+ macro nany (N:: Int , criterion:: Expr )
210
186
if criterion. head != :->
211
187
error (" Second argument must be an anonymous function expression yielding the criterion" )
212
188
end
213
- conds = [ Expr (:escape , inlineanonymous (criterion, i)) for i = 1 : N]
189
+ conds = Any[ Expr (:escape , inlineanonymous (criterion, i)) for i = 1 : N ]
214
190
Expr (:|| , conds... )
215
191
end
216
192
220
196
Generates an `N`-tuple. `@ntuple 2 i` would generate `(i_1, i_2)`, and `@ntuple 2 k->k+1`
221
197
would generate `(2,3)`.
222
198
"""
223
- macro ntuple (N, ex)
224
- _ntuple (N, ex)
225
- end
226
-
227
- function _ntuple (N:: Int , ex)
228
- vars = [ inlineanonymous (ex,i) for i = 1 : N ]
199
+ macro ntuple (N:: Int , ex)
200
+ vars = Any[ inlineanonymous (ex,i) for i = 1 : N ]
229
201
Expr (:escape , Expr (:tuple , vars... ))
230
202
end
231
203
0 commit comments