invenia/ExprTools.jl
Fork: 11 Star: 77 (更新于 1970-01-01 00:00:00)
license: MIT
Language: Julia .
Light-weight expression manipulation tools
最后发布版本: v0.1.10 ( 2023-07-28 03:48:40)
ExprTools
ExprTools provides tooling for working with Julia expressions during metaprogramming. This package aims to provide light-weight performant tooling without requiring additional package dependencies.
Alternatively see the MacroTools package for a more powerful set of tools.
Currently, this package provides the splitdef
, signature
and combinedef
functions which are useful for inspecting and manipulating function definition expressions.
-
splitdef
works on a function definition expression and returns aDict
of its parts. -
combinedef
takes aDict
fromsplitdef
and builds it into an expression. -
signature
works on aMethod
, or the type-tuplesig
field of a method, returning a similarDict
that holds the parts of the expressions that would form its signature.
As well as several helpers that are useful in combination with them.
-
args_tuple_expr
applies to aDict
fromsplitdef
orsignature
to generate an expression for a tuple of its arguments. -
parameters
which return the type-parameters of a type, and so is useful for working with the type-tuple that comes out of thesig
field of aMethod
e.g.
julia> using ExprTools
julia> ex = :(
function Base.f(x::T, y::T) where T
x + y
end
)
:(function Base.f(x::T, y::T) where T
#= none:3 =#
x + y
end)
julia> def = splitdef(ex)
Dict{Symbol,Any} with 5 entries:
:args => Any[:(x::T), :(y::T)]
:body => quote…
:name => :(Base.f)
:head => :function
:whereparams => Any[:T]
julia> def[:name] = :g;
julia> def[:head] = :(=);
julia> args_tuple_expr(def)
:((x, y))
julia> def[:body] = :(*($(args_tuple_expr(def))...));
julia> g_expr = combinedef(def)
:((g(x::T, y::T) where T) = (*)((x, y)...))
julia> eval(g_expr)
g (generic function with 1 method)
julia> g_method = first(methods(g))
g(x::T, y::T) where T in Main
julia> parameters(g_method.sig)
svec(typeof(g), T, T)
julia> signature(g_method)
Dict{Symbol, Any} with 3 entries:
:name => :g
:args => Expr[:(x::T), :(y::T)]
:whereparams => Any[:T]
JuliaCon 2021 Video
"ExprTools: Metaprogramming from reflection" by Lyndon White
最近版本更新:(数据更新于 1970-01-01 00:00:00)
2023-07-28 03:48:40 v0.1.10
2023-03-08 23:15:01 v0.1.9
2022-01-22 03:00:20 v0.1.8
2022-01-12 03:19:13 v0.1.7
2021-07-06 21:02:46 v0.1.6
2021-07-06 01:27:31 v0.1.5
2021-07-02 01:55:11 v0.1.4
2020-10-15 03:20:36 v0.1.3
2020-09-08 01:17:38 v0.1.2
2020-04-15 00:06:02 v0.1.1
invenia/ExprTools.jl同语言 Julia最近更新仓库
2024-09-13 13:29:38 jump-dev/JuMP.jl
2024-02-17 06:31:27 JuliaPackaging/BinaryBuilder.jl
2023-09-14 22:59:09 JuliaStats/GLM.jl
2023-08-29 00:30:41 andreasKroepelin/polylux
1970-01-01 00:00:00 cafaxo/Llama2.jl
1970-01-01 00:00:00 adigitoleo/PlateMotionRequests.jl