Skip to content

Commit 039e88f

Browse files
committed
Refactor after code suggestions
1 parent 881af87 commit 039e88f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/abstractnamedinteger.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ name(n::Name) = n.value
5050
@names x y ...
5151
5252
Short-hand notation for constructing "named symbols", i.e. objects that can be used as names.
53+
In other words, the following expressions are equivalent:
5354
54-
Evaluates to
5555
```julia
56-
x = Name(:x)
57-
y = Name(:y)
58-
...
56+
x, y, z = @names x y z
57+
x, y, z = Name.((:x, :y, :z))
5958
```
6059
"""
6160
macro names(symbols::Symbol...)
62-
exs = map(symbol -> Expr(:(=), symbol, Name(symbol)), symbols)
63-
return esc(Expr(:block, exs...))
61+
return :($(Name).(($(QuoteNode.(symbols)))))
6462
end
6563

6664
# vcat that works with combinations of tuples

test/test_basics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
453453
end
454454

455455
@testset "@names" begin
456-
@names x
457-
@names y z
456+
x = @names x
457+
y, z = @names y z
458458
@test x == Name(:x)
459459
@test y == Name(:y)
460460
@test z == Name(:z)

0 commit comments

Comments
 (0)