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: src/SimpleUnPack.jl
+32-15Lines changed: 32 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -3,45 +3,62 @@ module SimpleUnPack
3
3
export@unpack
4
4
5
5
"""
6
-
@unpack a, b, ... = rhs
6
+
@unpack a, b, ... = x
7
7
8
-
Destructure properties `a`, `b`, ... of `rhs` into variables of the same name.
8
+
Destructure properties `a`, `b`, ... of `x` into variables of the same name.
9
9
10
-
The behaviour of the macro is equivalent to `(; a, b, ...) = rhs` which was introduced in [Julia#39285](https://github.com/JuliaLang/julia/pull/39285) and is available in Julia >= 1.7.0-DEV.364.
10
+
The behaviour of the macro is equivalent to `(; a, b, ...) = x` which was introduced in [Julia#39285](https://github.com/JuliaLang/julia/pull/39285) and is available in Julia >= 1.7.0-DEV.364.
11
11
"""
12
-
macrounpack(args::Expr)
12
+
macrounpack(args)
13
13
returnunpack(args)
14
14
end
15
15
16
-
functionunpack(args::Expr)
16
+
functionunpack(args)
17
17
# Extract properties and RHS
18
18
if!Meta.isexpr(args, :(=), 2)
19
-
throw(ArgumentError("`@unpack` can only be applied to expressions of the form `a, b = c`"))
19
+
throw(
20
+
ArgumentError(
21
+
"`@unpack` can only be applied to expressions of the form `a, b, ... = x`"
22
+
),
23
+
)
20
24
end
21
25
lhs, rhs = args.args
22
26
properties =if lhs isa Symbol
23
27
[lhs]
24
-
elseif Meta.isexpr(lhs, :tuple) &&!isempty(lhs.args) &&all(x -> x isa Symbol, lhs.args)
28
+
elseif Meta.isexpr(lhs, :tuple) &&
29
+
!isempty(lhs.args) &&
30
+
all(x -> x isa Symbol, lhs.args)
25
31
lhs.args
26
32
else
27
-
throw(ArgumentError("`@unpack` can only be applied to expressions of the form `a, b = c`"))
33
+
throw(
34
+
ArgumentError(
35
+
"`@unpack` can only be applied to expressions of the form `a, b, ... = x`",
36
+
),
37
+
)
28
38
end
29
39
30
40
ifVERSION>=v"1.7.0-DEV.364"
31
41
# Fall back to destructuring in Base when available:
32
42
# https://github.com/JuliaLang/julia/pull/39285
33
-
returnExpr(:(=), Expr(:tuple, Expr(:parameters, (esc(p) for p in properties)...)), esc(rhs))
43
+
returnExpr(
44
+
:(=), Expr(:tuple, Expr(:parameters, (esc(p) for p in properties)...)), esc(rhs)
0 commit comments