-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
So apparently you can actually get the @& macro working. Now, Julia prevents you from doing this normally:
julia> macro &(blah)
esc(blah)
end
ERROR: ParseError:
# Error @ REPL[2]:1:7
macro &(blah)
# └─────┘ ── Invalid signature in macro definition
julia> macro :&(blah)
esc(blah)
end
ERROR: syntax: invalid macro definition around REPL[3]:1but inside an @eval, it's totally fine:
julia> let x = :&
@eval macro $(x)(blah)
return esc(blah)
end
end
@& (macro with 1 method)We could then literally have syntax like this:
@let x = @& yfor creating a reference to y. Perhaps these @let and @& macros could automatically adapt to the context...
function foo(x::@& Vector{Int}, y)
sum(x) + y
endthis would transform into OrBorrowed{Vector{Int}}.
@bc foo(@&(x), @& :mut y)this would be equivalent to @bc foo(x, @mut(y)) in the current notation.
@let x = [1, 2, 3] #= owned variable =#
@let :mut y = [4, 5] #= mutable owned variable =#
@let z = @& y #= immutable reference to y =#Only question is how to incorporate lifetimes here. I suppose ~lt just like the current @ref notation could be best?
Note that GitHub doesn't, but the Julia REPL renders these correctly:
Metadata
Metadata
Assignees
Labels
No labels
