fluxml / macrotools.jl Goto Github PK
View Code? Open in Web Editor NEWMacroTools provides a library of tools for working with Julia code and expressions.
Home Page: https://fluxml.ai/MacroTools.jl/stable/
License: Other
MacroTools provides a library of tools for working with Julia code and expressions.
Home Page: https://fluxml.ai/MacroTools.jl/stable/
License: Other
This is causing JuliaLang/julia#28221. At least for APIs that return a result instead of exposing MatchError
, the package should use return values instead of exceptions.
Call:
prettify(
quote
map(1:N) do n
f(n)
end
end
)
Result:
:(map(1:N) do n
f
n
end)
Expected:
:(map(1:N) do n
f(n)
end)
System info:
Manjaro Linux
Julia Version 0.7.0-rc2.0
Commit 78540cba4c (2018-08-02 19:14 UTC)
MacroTools v0.4.2
Seems like the latest tagged version (v0.3.7) lacks splitdef
Is there any way to match on expressions with a :$
head? Like, replacing
if isexpr(expr, :$)
@assert length(expr.args) == 1
:(shift($(esc(expr.args[1]))))
end
by
@match expr begin
($(e)) => :(shift($(esc(e))))
end
where expr
is, for example, defined as follows:
julia> expr = :(:($(sdf))).args[1]
:($(Expr(:$, :sdf)))
julia> dump(expr)
Expr
head: Symbol $
args: Array{Any}((1,))
1: Symbol sdf
I also tried interpolating the $
itself, but it didn't help:
julia> @match expr begin
($:$(e_)) => :(shift($(esc(e))))
end
(obviously, since the match expression of this is a Expr(:call, :$, :e_)
and not an interpolation).
I couldn't work out how to match types when slurping with __
:
block = quote
begin
north
east
south
west
end
end
Untyped slurping works:
symbols = @match block begin
begin
s__
end => s
end
but I wanted to match only Symbols
, so I tried this but didn't work:
symbols = @match block begin
begin
s__Symbol
end => s
end
julia> ex = :(f(x,y) = x+y) |> striplines;
julia> for i=1:10
global ex = @> ex longdef shortdef
end
julia> ex
:(f(x, y) = begin
begin
begin
begin
begin
begin
begin
begin
begin
begin
begin
x + y
end
end
end
end
end
end
end
end
end
end
end)
The reduce
keyword arg usages here:
have broken MacroTools on 0.6. This is the cause of JunoLab/Hiccup.jl#30.
Hey! I was playing with the package and I spotted a problem while trying unions in @capture
:
julia> using MacroTools
julia> versioninfo()
Julia Version 0.5.1
Commit 6445c82d00 (2017-03-05 13:25 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
WORD_SIZE: 64
BLAS: libopenblas (NO_AFFINITY SANDYBRIDGE)
LAPACK: liblapack
LIBM: libm
LLVM: libLLVM-3.7.1 (ORCJIT, ivybridge)
julia> macro m1(ex)
@capture(ex, f_(args__) = body_ | function f_(args__) body_ end) || return ex
@show f
@show args
@show body
return ex
end;
julia> macro m2(ex)
@capture(ex, (f_{T_}|f_)(args__) = body_) || return ex
@show f
@show args
@show body
return ex
end;
julia> macro m3(ex)
@capture(ex, f_(args__) = body_) || @capture(ex, function f_(args__) body_ end) || return ex
@show f
@show args
@show body
return ex
end;
julia> @m1 f(x) = 5x;
f = :f
args = Any[:x]
body = :(5x)
julia> @m1 function f(x) 5x end;
WARNING: Method definition f(Any) in module Main at REPL[6]:1 overwritten at REPL[7]:1.
julia> @m2 f(x) = 5x;
f = :f
args = Any[:x]
body = quote # REPL[8], line 1:
5x
end
WARNING: Method definition f(Any) in module Main at REPL[7]:1 overwritten at REPL[8]:1.
julia> @m3 f(x) = 5x;
f = :f
args = Any[:x]
body = quote # REPL[9], line 1:
5x
end
WARNING: Method definition f(Any) in module Main at REPL[8]:1 overwritten at REPL[9]:1.
julia> @m3 function f(x) 5x end;
f = :f
args = Any[:x]
body = quote # REPL[10], line 1:
5x
end
WARNING: Method definition f(Any) in module Main at REPL[9]:1 overwritten at REPL[10]:1.
Even though m1
and m2
are copies from README
, they don't work properly. I hope I am not missing some stupid mistake while trying.
I'd appreciate if you could help. Thanks!
Hi,
In julia 0.5.0-rc4+0
(OS X Yosemite 10.10.5), I'm having some trouble while loading MacroTools
and TaylorSeries
. At the REPL, I tried to run
julia> using MacroTools, TaylorSeries
and everything worked fine; but I also tried to run
julia> using TaylorSeries, MacroTools
and then I'm getting the following error:
ERROR: TypeError: Tuple: in non-final parameter, expected Type{T}, got Type{Vararg{Int64,N}}
in _include_from_serialized(::String) at ./loading.jl:150
in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:187
in _require_search_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:217
in _require_search_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at /Users/Jorge/julia/julia-9c76c3e89a/lib/julia/sys.dylib:?
in require(::Symbol) at ./loading.jl:371
in require(::Symbol) at /Users/Jorge/julia/julia-9c76c3e89a/lib/julia/sys.dylib:?
I also tested for this issue in julia 0.4.7-pre+3
but found no error there.
The tag name "0.3.8" is not of the appropriate SemVer form (vX.Y.Z).
cc: @MikeInnes
It appears that attempting to create an @match
that uses unions and expression types results in no matches being found. A few examples:
This works:
julia> @match :(x[1]) begin
(v_ref) => (v)
end
:(x[1])
But adding a union gives no match:
julia> @match :(x[1]) begin
(v_ref |
(v_ref <= ub_)) => (v)
end
Removing the _ref
tag fixes it:
julia> @match :(x[1]) begin
(v_ |
(v_ <= ub_)) => (v)
end
:(x[1])
Similarly, with a _Symbol
tag, this works:
julia> @match :(x) begin
(v_Symbol) => (v)
end
:x
and this doesn't:
@match :(x) begin
(v_Symbol |
(v_Symbol <= ub_)) => (v)
end
Do unions just not support type restrictions?
Not sure if this is a documentation issue or a bug, but order matters:
julia> (@capture :(struct Foo{X} end) struct (T_{params__}|T_) fields__ end), T
(true, :Foo)
julia> (@capture :(struct Foo{X} end) struct (T_|T_{params__}) fields__ end), T
(true, :(Foo{X}))
Sometimes I just depend on Lazy
for Lazy.@forward
, but the latter is already in MacroTools
, although unexported.
Perhaps it would make sense to move it to this package "officially", deprecating Lazy.@forward
. The functionality is not strongly tied to either package, but this would remove one dependency from those who just need this single macro.
Is now provided by base (causing method overwrite and stack overflow on master).
And macro expand should now splice in $__module__
as the first argument of the call to macroexpand.
They are super useful,
but it is hard to see what they do, even by reading the source code.
I'm looking into using the @formula
macro from the StatsModels
package, which allows using the |
operator. This is used e.g. by MixedModels
for random effect in groups.
However, I can't seem to parse it. Is it interfering with the usage of |
for MacroTools optionality?
MWE
@capture :(y~x|e~z) (left_|right_)
where the variable right
comes out empty.
Thanks!
The currently tagged versions produces a very large number of deprecation warnings on julia 0.5, master seems fine. With the RC0 out for julia 0.5, it would be great if you could tag a version very soon so that we can clean up all the deprecation avalanche that is hitting users right now :)
module MM
using MacroTools: @capture
@capture(:(x=2), _lhs = _rhs)
end
> UndefVarError: MacroTools not defined
It works if I import MacroTools. In my code, I usually fix this by writing function calls like $MacroTools.foo(...)
, but I don't use hygiene so I'm not sure if it's applicable in your case.
This is still definitely one of the most useful Julia packages for me, thank you!
I guess I'd like to have the option of having gensyms be converted to identifiers using some sort of deterministic naming scheme with minimal possibility for name collisions, like:
sym_id_1, sym_id_2, sym_id_3... etc. There are only so many animal names in animals.txt and I also worry that when the number of gensyms exceeds the number of animal names that this will lead to trouble.
Is there a reason why MacroTools.isexpr
is distinct from Base.Meta.isexpr
? They have slightly different interfaces, but on the whole it looks like they are trying to do the same thing.
It seems the pattern-matching syntax gets confused by the .
in the type:
julia> using MacroTools, Markdown
julia> @capture(md"_hello_", x_Markdown.MD)
false
julia> using Markdown: MD
julia> @capture(md"_hello_", x_MD)
true
After JuliaLang/julia#19449, soon to be merged for Julia 0.6, you will no longer be able to access the raw bytes of a string via string.data
; instead, do Vector{UInt8}(string)
. For example, this affects:
When I write macros acting on function expressions I often write a lot of code such that the macro works for different types of declarations. E.g:
@some_macro a(x)=1
@some_macro function a(x)
1
end
# or
@some_macro function a{T <: Float64}(x::T)
1
end
@some_macro function a(x) where T <: Float64
1
end
Since this leads to a lot of unnecessary macro code it would be nice if there was some sort of canonical form in which an expression could be converted to. MacroTools already has a function longdef
that does part of what is needed, but does not rewrite where
expressions. Do we want a function canonicaldef
or something similar that rewrites functions with where
syntax into the regular fn_name{targs...}(args...)
syntax? If that is the case is another proposals for the naming beside canonicaldef
? I would be happy to contribute that function in a pull request.
julia> using MacroTools
julia> macro foo(ex)
isa(ex,Expr) && ex.head == :$ ? 7 : ex
end
@foo (macro with 1 method)
julia> @foo $bar
7
julia> @expand @foo $bar
:bar
See also here
@capture
introduces assignments to variables indicated in its second argument. When one of these assignments is to a variable with the same name as the first argument, things seem to go wrong โ the match fails and the value of that variable is set to nothing
. I think the better behavior in this case would be for the match to succeed, and for ex
and b
in the second example to have the values of a
and b
in the first.
julia> ex = :(1 + 2)
:(1 + 2)
julia> @capture(ex, a_ + b_)
true
julia> @capture(ex, ex_ + b_)
false
julia> ex
The following failed. Is there a way to support this capture pattern?
julia> ex=:(Base:cat,hcat,vcat)
:((Base:cat, hcat, vcat))
julia> @capture(ex, M_:fs__)
false
Hi Mike,
do you want to set up a Documenter.jl doc? I can make a PR for this.
Bests,
Roger
Hi
MacroTools.splitarg(arg)
returns an error in julia v0.7:
julia> arg=:(a::Int=0)
:(a::Int = 0)
julia> MacroTools.splitarg(arg)
ERROR: UndefVarError: name not defined
Stacktrace:
[1] macro expansion at /Users/ben/.julia/v0.7/MacroTools/src/utils.jl:286 [inlined]
[2] macro expansion at /Users/ben/.julia/v0.7/MacroTools/src/macro.jl:14 [inlined]
[3] (::getfield(MacroTools, Symbol("#splitvar#28")))(::Expr) at /Users/ben/.julia/v0.7/MacroTools/src/utils.jl:283
[4] splitarg(::Expr) at /Users/ben/.julia/v0.7/MacroTools/src/utils.jl:292
In Julia 0.4, the first example from the README yields:
ex = quote
type Foo
x::Int
y
end
end
@match ex begin
type T_
fields__
end => (T, fields)
end
> (:Foo,Any[quote # In[65], line 3:
> x::Int # In[65], line 4:
> y
> end])
The second value in the tuple is a one-element array,
Array(Any,(1,))
1: Expr
head: Symbol block
args: Array(Any,(4,))
1: LineNumberNode
file: Symbol In[66]
line: Int64 3
2: Expr
head: Symbol ::
args: Array(Any,(2,))
1: Symbol x
2: Symbol Int
typ: Any
3: LineNumberNode
file: Symbol In[66]
line: Int64 4
4: Symbol y
typ: Any
Whereas the README promises
(:Foo,{:(x::Int),:y})
While reading the Flux sources I see @forward
a lot. I've tracked it to this package but as I'm new to Julia I can't tell if it's obtuse or I can't read macros yet. Either way some documentation, in the readme or 'proper', would be nice.
I'm trying to get all the fields in a type with
@match e begin
type typename_
fields__
end -> (typename, fields)
which works as expected if
e=quote
type T
x
y
end
end
but doesn't match if
e=quote
type T
x
end
end
I don't know if it is intended, but splitarg
errors if there are keyword arguments after the ;
, it'd be very useful if it could also recognize those (just like splitdef
does):
julia> map(splitarg, (:(f(a=2, x::Int=nothing, y; z = 12))).args[2:end])
ERROR: TypeError: splitvar: in typeassert, expected Symbol, got Expr
Stacktrace:
[1] macro expansion at /Users/pietro/.julia/v0.6/MacroTools/src/utils.jl:287 [inlined]
[2] macro expansion at /Users/pietro/.julia/v0.6/MacroTools/src/macro.jl:14 [inlined]
[3] (::MacroTools.#splitvar#28)(::Expr) at /Users/pietro/.julia/v0.6/MacroTools/src/utils.jl:283
[4] splitarg(::Expr) at /Users/pietro/.julia/v0.6/MacroTools/src/utils.jl:294
[5] _collect(::Array{Any,1}, ::Base.Generator{Array{Any,1},MacroTools.#splitarg}, ::Base.EltypeUnknown, ::Base.HasShape) at ./array.jl:454
[6] map(::Function, ::Array{Any,1}) at ./abstractarray.jl:1865
julia> @q @time(1+1)
:(#= REPL[5]:1 =# @time 1 + 1)
It could be fixed by postwalking and changing all the :macrocall
s to have nothing
for the line number, I believe?
MacroTools can't match macros when they appear in the type assertions in function calls. This seems like a crazy issue, but a key macro in my package depended on this functionality and now something has changed with the latest julia build and things fail. Any ideas as to why this match failure would happen?
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.7.0-DEV.5246 (2018-05-29 13:27 UTC)
_/ |\__'_|_|_|\__'_| | Commit 082be9a (8 days old master)
|__/ | x86_64-apple-darwin17.5.0
(v0.7) pkg> up MacroTools
Updating registry at `~/.julia/registries/Uncurated`
Updating git-repo `https://github.com/JuliaRegistries/Uncurated.git`
Resolving package versions...
Updating `~/.julia/environments/v0.7/Project.toml`
[no changes]
Updating `~/.julia/environments/v0.7/Manifest.toml`
[no changes]
julia> using MacroTools
julia> x = :(foo(x::@bar(qux))).args[2].args[2]
:(#= REPL[3]:1 =# @bar qux)
julia> :(@bar(qux))
:(#= REPL[4]:1 =# @bar qux)
julia> x.head
:macrocall
julia> :(@bar(qux)).head
:macrocall
julia> x.args
3-element Array{Any,1}:
Symbol("@bar")
:(#= REPL[3]:1 =#)
:qux
julia> :(@bar(qux)).args
3-element Array{Any,1}:
Symbol("@bar")
:(#= REPL[8]:1 =#)
:qux
julia> @capture(x, @bar(qux))
false
julia> @capture(:(@bar(qux)), @bar(qux))
true
EDIT: It appears that this has something to do with line number nodes getting passed as arguments to macros. I rolled a custom solution for myself, but I'll dig into this sometime when I have more time. I don't think this has anything to do with the type assertions at all now.
With c41c09b the @match
documentation was removed. Was that intentional? The commit title doesn't suggest so.
I had generated code that had line numbers embedded at all levels.
Here's a recursive version to strip them out, though I expect you can rewrite it in a much simpler way:
function rmlines!(ex)
n = length(ex.args)
i = 1
while i <= n
if isa(ex.args[i], Expr)
if ex.args[i].head == :line
deleteat!(ex.args, i)
n -= 1
continue
else
rmlines!(ex.args[i])
end
end
i += 1
end
end
> using MacroTools
ERROR: LoadError: LoadError: UndefVarError: readstring not defined
in include at /usr/local/lib/julia/sys.dylib
in include_from_node1 at /usr/local/lib/julia/sys.dylib
in include at /usr/local/lib/julia/sys.dylib
in include_from_node1 at /usr/local/lib/julia/sys.dylib
in require at /usr/local/lib/julia/sys.dylib
while loading /Users/michael/.julia/v0.4/MacroTools/src/utils.jl, in expression starting on line 77
while loading /Users/michael/.julia/v0.4/MacroTools/src/MacroTools.jl, in expression starting on line 9
> Pkg.status()
46 required packages:
- Atom 0.4.2+ master
- Bio 0.1.0+ phyloplot
- Blink 0.3.4+ master
- Bootstrap 0.3.3
- Cairo 0.2.31
- CodeTools 0.3.0+ master
- Color 0.2.11
- ColorBrewer 0.3.0
- Colors 0.6.3
- Compose 0.4.2
- DataFrames 0.7.0
- DataFramesMeta 0.1.1
- DataStructures 0.4.4
- Dates 0.4.4
- Distributions 0.8.10
- EcologicalNetwork 1.0.1
- FactCheck 0.4.2
- FunctionalData 0.1.0
- GLM 0.5.1
- GLPlot 0.0.5
- Gadfly 0.4.2
- GeoInterface 0.0.1
- Geodesy 0.0.1
- GreatCircle 0.0.1
- IJulia 1.1.9
- ImageView 0.1.19
- Images 0.5.4
- JLD 0.5.9
- Lint 0.2.3
- MAT 0.2.14
- MixedModels 0.4.5
- NamedArrays 0.4.7
- OpenStreetMap 0.8.2
- Pandas 0.2.0
- Phylogenetics 0.0.2
- PlotlyJS 0.1.4
- Plots 0.5.4+ master
- QuartzImageIO 0.1.2
- RCall 0.4.0
- RDatasets 0.1.3
- Roots 0.1.26 master
- SFML 0.1.0
- Shapefile 0.0.3
- Stats 0.1.0
- TestImages 0.1.1
- Yeppp 0.0.10
90 additional packages:
- ArrayViews 0.6.4
- BinDeps 0.3.21
- Blosc 0.1.4
- BufferedStreams 0.0.3
- Calculus 0.1.14
- Codecs 0.1.5
- ColorTypes 0.2.2
- ColorVectorSpace 0.1.3
- Combinatorics 0.2.1
- Compat 0.7.14
- Conda 0.1.9
- Contour 0.1.0
- DataArrays 0.2.20
- Distances 0.3.0
- Docile 0.5.23
- DualNumbers 0.2.2
- FileIO 0.0.5
- FixedPointNumbers 0.1.3
- FixedSizeArrays 0.1.0
- ForwardDiff 0.1.6
- GLAbstraction 0.0.12
- GLFW 1.1.2
- GLText 0.0.4
- GLWindow 0.1.2
- GMT 0.0.0- master (unregistered)
- GZip 0.2.18
- GeometryTypes 0.1.4
- Graphics 0.1.3
- Graphs 0.6.0
- Grid 0.4.0
- HDF5 0.5.8
- Hexagons 0.0.4
- Hiccup 0.0.2
- Homebrew 0.2.0
- HttpCommon 0.2.4
- HttpParser 0.1.1
- HttpServer 0.1.5
- ImmutableArrays 0.0.11
- IniFile 0.2.5
- IntervalTrees 0.0.5
- Iterators 0.1.9
- JSON 0.5.0
- JuliaParser 0.6.4
- KernelDensity 0.1.2
- LNR 0.0.2
- LaTeXStrings 0.1.6
- Lazy 0.10.1
- Lexicon 0.1.18
- LibExpat 0.1.2
- Libz 0.0.2
- LightXML 0.2.1
- Loess 0.0.6
- Logging 0.2.0
- MacroTools 0.3.0+ master
- MathProgBase 0.4.3
- MbedTLS 0.2.2
- Measures 0.0.2
- Media 0.1.2
- ModernGL 0.0.7
- Mustache 0.0.14
- Mux 0.2.0
- NLopt 0.3.1
- NaNMath 0.2.1
- Nettle 0.2.3
- Optim 0.4.4
- PDMats 0.4.1
- Polynomials 0.0.5
- PyCall 1.4.0
- PyPlot 2.1.1
- Quaternions 0.1.0
- RasterIO 0.0.0- master (unregistered)
- Reactive 0.3.2
- Reexport 0.0.3
- Requires 0.2.2
- SHA 0.1.2
- SIUnits 0.0.6
- Showoff 0.0.6
- SortingAlgorithms 0.0.6
- StatsBase 0.8.0
- StatsFuns 0.2.0
- Switch 0.0.1
- TexExtensions 0.0.3
- Tk 0.3.7
- URIParser 0.1.3
- WebSockets 0.1.2
- Winston 0.11.13
- WoodburyMatrices 0.1.5
- ZMQ 0.3.1
- ZipFile 0.2.6
- Zlib 0.1.12
Thank you for MacroTools, it's super useful! I think I found a bug
let ex = :(function foo(a, b, c; kw=1) a+b+c end)
@capture(ex, function foo(arg1_, args__) body__ end)
arg1
end
> :($(Expr(:parameters, :(x=1))))
It works fine without kw=1
longdef1
gets rid of line numbers:
julia> fun = :(f(x) = x+2)
:(f(x) = begin
#= REPL[37]:1 =#
x + 2
end)
julia> MacroTools.longdef1(fun)
:(function f(x)
x + 2
end)
And since it's relied upon by splitdef
, we lose line numbers there too.
It would be useful for manipulating anonymous functions. Currently it shows:
julia> splitdef(:(x->x))
ERROR: AssertionError: Not a function definition: x->begin
#= REPL[30]:1 =#
x
end
Just in case you didn't spot this on Travis nightly:
ERROR: LoadError: LoadError: StackOverflowError:
Stacktrace:
[1] include_from_node1(::Module, ::String) at ./loading.jl:549
[2] include(::Module, ::String) at ./sysimg.jl:14
[3] include(::String) at /home/travis/.julia/v0.7/MacroTools/src/MacroTools.jl:2
[4] include_from_node1(::Module, ::String) at ./loading.jl:549
[5] include(::Module, ::String) at ./sysimg.jl:14
[6] anonymous at ./<missing>:2
while loading /home/travis/.julia/v0.7/MacroTools/src/utils.jl, in expression starting on line 96
while loading /home/travis/.julia/v0.7/MacroTools/src/MacroTools.jl, in expression starting on line 12
I didn't know I was using this, but I've added a Juno.jl dependency so it looks like I am... :)
We're having a heck of a time debugging ONNX.jl given that it uses MacroTools.alias_gensyms in generating it's output. The problem is that given the same inputs, we always get a different output (alias_gensyms replaces gensysms with animal names). This makes it very difficult to compare two different outputs from ONNX.jl.
I see where the "problem" is (from our perspective), it's in the init function in src/MacroTools.jl, specifically, this line:
Compat.Random.shuffle!(animals)
In retrospect it is pretty obvious, but I needed to look up the associativity of =>
to figure out how to match Pair(x,y)
expressions, ie
@match :(a => b) begin
(x_ => y_) => (x,y) # need parentheses
_ => :unmatched
end
where x_ => y_ => (x,y)
won't work because it is parsed as x_ => (y_ => (x,y))
. Thanks for the great package, if you consider this issue too trivial just close it.
The tag name "0.3.3" is not of the appropriate SemVer form (vX.Y.Z).
cc: @ranjanan
This definitely isn't a high priority issue, but rmlines used here (and also in Lazy.jl) messes up code coverage statistics. I've been struggling with this in ChainMap.jl. See
https://github.com/bramtayl/ChainMap.jl/blob/master/src/chain.jl
for one way to work around this when chaining (although I'm not sure whether or not a similar strategy could work for MacroTools).
Just discovered this very nice package, thanks!
The following works:
julia> using MacroTools
julia> ex = :(x <= 1)
:(x <= 1)
julia> @match ex begin
a_ <= b_ => (a,b)
end
(:x,1)
but this union doesn't:
julia> @match ex begin
(a_ <= b_ | a_ < b_) => (a,b)
end
(returns nothing).
Am I misunderstanding something?
I'm relatively confident that the PR JuliaLang/julia#23553 is the reason the following example breaks when trying to use julia compiled from master:
julia> using MacroTools; using MacroTools: @q
...
julia> @match :(function tryme(x); x; end) begin
function f_(args__) body_ end => @q $f($args...) = $body
end
ERROR: UndefVarError: f not defined
I've put together a patch to the internal function bindinglet
which seems to fix the issue โ I could probably work up a pull request for it. (I'm mostly a github lurker, so rather unfamiliar with the process...)
I think there's a bug where a kw expression will turn into an assignment:
e = Expr(:kw, :a, 1)
enew = MacroTools.@match e begin
a_ => a
end
e.head != enew.head
On 0.6:
@capture(:(function foo(x) x+x end), function (fcall_ | fcall_) body_ end) # true
@capture(:(function foo(x) x+x end), function (fcall_) body_ end) # false
@capture(:(function foo(x) x+x end), function fcall_ body_ end) # syntax error
I get that there isn't anything to be done about the last case, but it's weird that number one and number two aren't equivalent.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.