VERSION
v"1.7.0-DEV.1133"
if isfile("Project.toml")
using Pkg
Pkg.activate(".")
using Revise
end
Activating project at `C:\Users\genkuroki\OneDrive\work\MetaUtils.jl`
using MetaUtils
@show_sexpr 2x+1
(:call, :+, (:call, :*, 2, :x), 1)
x = 10; (:call, :+, (:call, :*, 2, :x), 1) |> teval
21
@show_tree 2x+1
Expr(:call) ├─ :+ ├─ Expr(:call) │ ├─ :* │ ├─ 2 │ └─ :x └─ 1
show_tree(:(2x + 1))
Expr(:call) ├─ :+ ├─ Expr(:call) │ ├─ :* │ ├─ 2 │ └─ :x └─ 1
print_subtypes(AbstractRange)
AbstractRange ├─ LinRange ├─ OrdinalRange │ ├─ AbstractUnitRange │ │ ├─ Base.IdentityUnitRange │ │ ├─ Base.OneTo │ │ ├─ Base.Slice │ │ └─ UnitRange │ └─ StepRange └─ StepRangeLen
show_expr(:(f(x, g(y, z))))
Expr(:call, :f, :x, Expr(:call, :g, :y, :z))
@show_expr 2x+1
Expr(:call, :+, Expr(:call, :*, 2, :x), 1)
x = 10; Expr(:call, :+,
Expr(:call, :*, 2, :x), 1) |> eval
21
show_texpr(:(f(x, g(y, z))))
(:call, :f, :x, (:call, :g, :y, :z))
@show_texpr 2x+1
(:call, :+, (:call, :*, 2, :x), 1)
x = 10; (:call, :+,
(:call, :*, 2, :x), 1) |> teval
21
texpr2expr((:call, :sin, (:call, :/, π, 6)))
:(sin(π / 6))
(:call, :sin, (:call, :/, π, 6)) |> teval
0.49999999999999994
@teval (:call, :sin, (:call, :/, π, 6))
0.49999999999999994
MetaUtils.@t (:call, :sin, (:call, :/, π, 6))
:(sin(π / 6)) → 0.49999999999999994
MetaUtils.@T (:call, :sin, (:call, :/, π, 6))
(:call, :sin, (:call, :/, π, 6)) → (:call, :sin, (:call, :/, π, 6)) → :(sin(π / 6)) → 0.49999999999999994
(:sin, (:/, π, 6)) |> teval
0.49999999999999994
@teval (:sin, (:/, π, 6))
0.49999999999999994
MetaUtils.@t (:sin, (:/, π, 6))
:(sin(π / 6)) → 0.49999999999999994
MetaUtils.@T (:sin, (:/, π, 6))
(:sin, (:/, π, 6)) → (:call, :sin, (:call, :/, π, 6)) → :(sin(π / 6)) → 0.49999999999999994
@show_texpr for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end
(:for, (:(=), :k, (:call, :(:), 1, 10)), (:block, (:(=), :x, (:call, :÷, (:call, :*, :k, (:call, :+, :k, 1)), 2)), (:call, :println, "k(k+1)/2 = ", :x)))
@show_texpr for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end true
(:for, (:(=), :k, (:call, :(:), 1, 10)), (:block, LineNumberNode(2, Symbol("In[25]")), (:(=), :x, (:call, :÷, (:call, :*, :k, (:call, :+, :k, 1)), 2)), LineNumberNode(3, Symbol("In[25]")), (:call, :println, "k(k+1)/2 = ", :x)))
@show_tree for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end 2
Expr(:for) ├─ Expr(:(=)) │ ├─ :k │ └─ Expr(:call) │ ⋮ │ └─ Expr(:block) ├─ Expr(:(=)) │ ⋮ │ └─ Expr(:call) ⋮
@show_tree for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end
Expr(:for) ├─ Expr(:(=)) │ ├─ :k │ └─ Expr(:call) │ ├─ :(:) │ ├─ 1 │ └─ 10 └─ Expr(:block) ├─ Expr(:(=)) │ ├─ :x │ └─ Expr(:call) │ ├─ :÷ │ ├─ Expr(:call) │ │ ├─ :* │ │ ├─ :k │ │ └─ Expr(:call) │ │ ├─ :+ │ │ ├─ :k │ │ └─ 1 │ └─ 2 └─ Expr(:call) ├─ :println ├─ "k(k+1)/2 = " └─ :x
@show_tree for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end 10 true
Expr(:for) ├─ Expr(:(=)) │ ├─ :k │ └─ Expr(:call) │ ├─ :(:) │ ├─ 1 │ └─ 10 └─ Expr(:block) ├─ :(#= In[28]:2 =#) ├─ Expr(:(=)) │ ├─ :x │ └─ Expr(:call) │ ├─ :÷ │ ├─ Expr(:call) │ │ ├─ :* │ │ ├─ :k │ │ └─ Expr(:call) │ │ ├─ :+ │ │ ├─ :k │ │ └─ 1 │ └─ 2 ├─ :(#= In[28]:3 =#) └─ Expr(:call) ├─ :println ├─ "k(k+1)/2 = " └─ :x
Meta.@dump for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end
Expr head: Symbol for args: Array{Any}((2,)) 1: Expr head: Symbol = args: Array{Any}((2,)) 1: Symbol k 2: Expr head: Symbol call args: Array{Any}((3,)) 1: Symbol : 2: Int64 1 3: Int64 10 2: Expr head: Symbol block args: Array{Any}((4,)) 1: LineNumberNode line: Int64 2 file: Symbol In[29] 2: Expr head: Symbol = args: Array{Any}((2,)) 1: Symbol x 2: Expr head: Symbol call args: Array{Any}((3,)) 1: Symbol ÷ 2: Expr 3: Int64 2 3: LineNumberNode line: Int64 3 file: Symbol In[29] 4: Expr head: Symbol call args: Array{Any}((3,)) 1: Symbol println 2: String "k(k+1)/2 = " 3: Symbol x
@show_expr for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end
Expr(:for, Expr(:(=), :k, Expr(:call, :(:), 1, 10)), Expr(:block, Expr(:(=), :x, Expr(:call, :÷, Expr(:call, :*, :k, Expr(:call, :+, :k, 1)), 2)), Expr(:call, :println, "k(k+1)/2 = ", :x)))
@show_texpr for k in 1:10
x = k*(k+1) ÷ 2
println("k(k+1)/2 = ", x)
end
(:for, (:(=), :k, (:call, :(:), 1, 10)), (:block, (:(=), :x, (:call, :÷, (:call, :*, :k, (:call, :+, :k, 1)), 2)), (:call, :println, "k(k+1)/2 = ", :x)))
print_subtypes(AbstractRange)
AbstractRange ├─ LinRange ├─ OrdinalRange │ ├─ AbstractUnitRange │ │ ├─ Base.IdentityUnitRange │ │ ├─ Base.OneTo │ │ ├─ Base.Slice │ │ └─ UnitRange │ └─ StepRange └─ StepRangeLen
print_subtypes(Number)
Number ├─ Complex └─ Real ├─ AbstractFloat │ ├─ BigFloat │ ├─ Float16 │ ├─ Float32 │ └─ Float64 ├─ AbstractIrrational │ └─ Irrational ├─ Integer │ ├─ Bool │ ├─ Signed │ │ ├─ BigInt │ │ ├─ Int128 │ │ ├─ Int16 │ │ ├─ Int32 │ │ ├─ Int64 │ │ └─ Int8 │ └─ Unsigned │ ├─ UInt128 │ ├─ UInt16 │ ├─ UInt32 │ ├─ UInt64 │ └─ UInt8 └─ Rational
print_subtypes(AbstractVector)
AbstractVector ├─ AbstractRange │ ├─ LinRange │ ├─ OrdinalRange │ │ ├─ AbstractUnitRange │ │ │ ├─ Base.IdentityUnitRange │ │ │ ├─ Base.OneTo │ │ │ ├─ Base.Slice │ │ │ └─ UnitRange │ │ └─ StepRange │ └─ StepRangeLen ├─ Base.ExceptionStack ├─ Base.LogicalIndex ├─ Base.MethodList ├─ Base.ReinterpretArray{T, 1, S, A} where {T, S, A<:(AbstractArray{S})} ├─ Base.ReshapedArray{T, 1} where T ├─ BitVector ├─ CartesianIndices{1, R} where R<:Tuple{OrdinalRange{Int64, Int64}} ├─ Core.Compiler.AbstractRange │ ├─ Core.Compiler.LinRange │ ├─ Core.Compiler.OrdinalRange │ │ ├─ Core.Compiler.AbstractUnitRange │ │ │ ├─ Core.Compiler.IdentityUnitRange │ │ │ ├─ Core.Compiler.OneTo │ │ │ ├─ Core.Compiler.Slice │ │ │ ├─ Core.Compiler.StmtRange │ │ │ └─ Core.Compiler.UnitRange │ │ └─ Core.Compiler.StepRange │ └─ Core.Compiler.StepRangeLen ├─ Core.Compiler.BitArray{1} ├─ Core.Compiler.ExceptionStack ├─ Core.Compiler.LinearIndices{1, R} where R<:Tuple{Core.Compiler.AbstractUnitRange{Int64}} ├─ Core.Compiler.MethodList ├─ DenseVector │ ├─ Base.CodeUnits │ ├─ Base.Experimental.Const{T, 1} where T │ ├─ Random.UnsafeView │ ├─ SharedArrays.SharedVector │ └─ Vector ├─ LinearIndices{1, R} where R<:Tuple{AbstractUnitRange{Int64}} ├─ PermutedDimsArray{T, 1} where T ├─ SparseArrays.AbstractSparseVector │ └─ SparseArrays.SparseVector ├─ SubArray{T, 1} where T ├─ Test.GenericArray{T, 1} where T └─ ZMQ.Message
@show_texpr function f(x::T) where T<:Number
sin(x)
end
(:function, (:where, (:call, :f, (:(::), :x, :T)), (:<:, :T, :Number)), (:block, (:call, :sin, :x)))
@show_tree function f(x::T) where T<:Number
sin(x)
end
Expr(:function) ├─ Expr(:where) │ ├─ Expr(:call) │ │ ├─ :f │ │ └─ Expr(:(::)) │ │ ├─ :x │ │ └─ :T │ └─ Expr(:<:) │ ├─ :T │ └─ :Number └─ Expr(:block) └─ Expr(:call) ├─ :sin └─ :x
@show_expr function f(x::T) where T<:Number
sin(x)
end
Expr(:function, Expr(:where, Expr(:call, :f, Expr(:(::), :x, :T)), Expr(:<:, :T, :Number)), Expr(:block, Expr(:call, :sin, :x)))
@show_texpr function f(x::T) where T<:Number
sin(x)
end
(:function, (:where, (:call, :f, (:(::), :x, :T)), (:<:, :T, :Number)), (:block, (:call, :sin, :x)))
@show_tree @show float(π)
Expr(:macrocall) ├─ Symbol("@show") ├─ :(#= In[39]:1 =#) └─ Expr(:call) ├─ :float └─ :π
@show_sexpr @show float(π)
(:macrocall, Symbol("@show"), :(#= In[40]:1 =#), (:call, :float, :π))
@teval (:macrocall, Symbol("@show"), :(#= In[34]:1 =#), (:call, :float, :π))
float(π) = 3.141592653589793
3.141592653589793
@show_expr @show float(π)
Expr(:macrocall, Symbol("@show"), LineNumberNode(1, Symbol("In[42]")), Expr(:call, :float, :π))
Expr(:macrocall, Symbol("@show"), LineNumberNode(@__LINE__, @__FILE__),
Expr(:call, :float, :π)) |> show_expr
Expr(:macrocall, Symbol("@show"), LineNumberNode(1, Symbol("In[43]")), Expr(:call, :float, :π))
Expr(:macrocall, Symbol("@show"), LineNumberNode(@__LINE__, @__FILE__),
Expr(:call, :float, :π)) |> eval
float(π) = 3.141592653589793
3.141592653589793
@show_texpr @show float(π)
(:macrocall, Symbol("@show"), LineNumberNode(1, Symbol("In[45]")), (:call, :float, :π))
(:macrocall, Symbol("@show"), LineNumberNode(@__LINE__, @__FILE__),
(:call, :float, :π)) |> teval
float(π) = 3.141592653589793
3.141592653589793
@teval (:macrocall, Symbol("@show"), LineNumberNode(@__LINE__, @__FILE__),
(:call, :float, :π))
float(π) = 3.141592653589793
3.141592653589793
QuoteNode(:(sin(x)))
:($(QuoteNode(:(sin(x)))))
QuoteNode(:(sin(x))) |> Meta.show_sexpr
(:quote, #QuoteNode (:call, :sin, :x) )
QuoteNode(:(sin(x))) |> show_expr
QuoteNode( Expr(:call, :sin, :x))
QuoteNode(:(sin(x))) |> show_texpr
QuoteNode( (:call, :sin, :x))
QuoteNode(
(:call, :sin, :x)) |> texpr2expr == QuoteNode(:(sin(x)))
true
@teval QuoteNode(
(:call, :sin, :x))
:(sin(x))
If you want more Lisp-like examamples, see LispLikeEval.ipynb.
using MetaUtils: @t, @T
# Define and run a function f(x) = sin(x)
@t (:(=), :(f(x)), (:sin, :x))
println()
@t (:f, (:/, π, 6))
:(f(x) = sin(x)) → f :(f(π / 6)) → 0.49999999999999994
# Define and run a function f(x) = sin(x)
@T (:(=), :(f(x)), (:sin, :x))
println()
@T (:f, (:/, π, 6))
(:(=), :(f(x)), (:sin, :x)) → (:(=), (:call, :f, :x), (:call, :sin, :x)) → :(f(x) = sin(x)) → f (:f, (:/, π, 6)) → (:call, :f, (:call, :/, π, 6)) → :(f(π / 6)) → 0.49999999999999994
# Define and run a function g(x) = sin(x)
@t (:block,
(:function, :(g(x)), (:sin, :x)),
(:call, :g, (:/, π, 6)))
quote function g(x) sin(x) end g(π / 6) end → 0.49999999999999994
# Define and run a function g(x) = sin(x)
@T (:block,
(:function, :(g(x)), (:sin, :x)),
(:call, :g, (:/, π, 6)))
(:block, (:function, :(g(x)), (:sin, :x)), (:call, :g, (:/, π, 6))) → (:block, (:function, (:call, :g, :x), (:call, :sin, :x)), (:call, :g, (:call, :/, π, 6))) → quote function g(x) sin(x) end g(π / 6) end → 0.49999999999999994
# Calculation of pi by the Monte Carlo method
@t (:block,
(:function, :(pi_mc(N)),
(:block,
(:(=), :c, 0),
(:for, (:(=), :i, (:(:), 1, :N)),
(:block,
(:+=, :c,
(:call, :ifelse,
(:≤, (:+, (:^, (:rand,), 2), (:^, (:rand,), 2)), 1),
1, 0)))),
(:/, (:*, 4, :c), :N))),
(:call, :pi_mc, (:^, 10, 8)))
quote function pi_mc(N) c = 0 for i = 1:N c += ifelse(rand() ^ 2 + rand() ^ 2 ≤ 1, 1, 0) end (4c) / N end pi_mc(10 ^ 8) end → 3.14178092
# quote
@t (:quote, (:sin, :x))
:($(Expr(:quote, :(sin(x))))) → :(sin(x))
# tuple
@t (:tuple, 1, 2, 3)
:((1, 2, 3)) → (1, 2, 3)
begin
using Plots
n = 20
x = range(-π, π; length=20)
noise = 0.3randn(n)
y = sin.(x) + noise
X = x .^ (0:3)'
b = X\y
f(x) = evalpoly(x, b)
xs = range(-π, π; length=400)
plot(; legend=:topleft)
scatter!(x, y; label="sample")
plot!(xs, sin.(xs); label="sin(x)", color=:blue, ls=:dash)
plot!(xs, f.(xs); label="degree-3 polynomial", color=:red, lw=2)
end
@show_texpr begin
using Plots
n = 20
x = range(-π, π; length=20)
noise = 0.3randn(n)
y = sin.(x) + noise
X = x .^ (0:3)'
b = X\y
f(x) = evalpoly(x, b)
xs = range(-π, π; length=400)
plot(; legend=:topleft)
scatter!(x, y; label="sample")
plot!(xs, sin.(xs); label="sin(x)", color=:blue, ls=:dash)
plot!(xs, f.(xs); label="degree-3 polynomial", color=:red, lw=2)
end
(:block, (:using, (:., :Plots)), (:(=), :n, 20), (:(=), :x, (:call, :range, (:parameters, (:kw, :length, 20)), (:call, :-, :π), :π)), (:(=), :noise, (:call, :*, 0.3, (:call, :randn, :n))), (:(=), :y, (:call, :+, (:., :sin, (:tuple, :x)), :noise)), (:(=), :X, (:call, :.^, :x, (Symbol("'"), (:call, :(:), 0, 3)))), (:(=), :b, (:call, :\, :X, :y)), (:(=), (:call, :f, :x), (:block, (:call, :evalpoly, :x, :b))), (:(=), :xs, (:call, :range, (:parameters, (:kw, :length, 400)), (:call, :-, :π), :π)), (:call, :plot, (:parameters, (:kw, :legend, QuoteNode(:topleft)))), (:call, :scatter!, (:parameters, (:kw, :label, "sample")), :x, :y), (:call, :plot!, (:parameters, (:kw, :label, "sin(x)"), (:kw, :color, QuoteNode(:blue)), (:kw, :ls, QuoteNode(:dash))), :xs, (:., :sin, (:tuple, :xs))), (:call, :plot!, (:parameters, (:kw, :label, "degree-3 polynomial"), (:kw, :color, QuoteNode(:red)), (:kw, :lw, 2)), :xs, (:., :f, (:tuple, :xs))))
@teval (:block,
(:using, (:., :Plots)),
(:(=), :n, 20),
(:(=), :x, (:range, (:parameters, (:kw, :length, 20)), (:-, :π), :π)),
(:(=), :noise, (:*, 0.3, (:randn, :n))),
(:(=), :y, (:+, (:., :sin, (:tuple, :x)), :noise)),
(:(=), :X, (:call, :.^, :x, (Symbol("'"), (:call, :(:), 0, 3)))),
(:(=), :b, (:\, :X, :y)),
(:(=), (:call, :f, :x), (:block, (:call, :evalpoly, :x, :b))),
(:(=), :xs, (:range, (:parameters, (:kw, :length, 400)), (:-, :π), :π)),
(:plot, (:parameters, (:kw, :legend, QuoteNode(:topleft)))),
(:scatter!, (:parameters, (:kw, :label, "sample")), :x, :y),
(:plot!, (:parameters,
(:kw, :label, "sin(x)"),
(:kw, :color, QuoteNode(:blue)),
(:kw, :ls, QuoteNode(:dash))),
:xs, (:., :sin, (:tuple, :xs))),
(:plot!, (:parameters,
(:kw, :label, "degree-3 polynomial"),
(:kw, :color, QuoteNode(:red)),
(:kw, :lw, 2)),
:xs, (:., :f, (:tuple, :xs))))
(:block,
(:using, (:., :Plots)),
(:(=), :n, 20),
(:(=), :x, (:range, (:parameters, (:kw, :length, 20)), (:-, :π), :π)),
(:(=), :noise, (:*, 0.3, (:randn, :n))),
(:(=), :y, (:+, (:., :sin, (:tuple, :x)), :noise)),
(:(=), :X, (:call, :.^, :x, (Symbol("'"), (:call, :(:), 0, 3)))),
(:(=), :b, (:\, :X, :y)),
(:(=), (:call, :f, :x), (:block, (:call, :evalpoly, :x, :b))),
(:(=), :xs, (:range, (:parameters, (:kw, :length, 400)), (:-, :π), :π)),
(:plot, (:parameters, (:kw, :legend, QuoteNode(:topleft)))),
(:scatter!, (:parameters, (:kw, :label, "sample")), :x, :y),
(:plot!, (:parameters,
(:kw, :label, "sin(x)"),
(:kw, :color, QuoteNode(:blue)),
(:kw, :ls, QuoteNode(:dash))),
:xs, (:., :sin, (:tuple, :xs))),
(:plot!, (:parameters,
(:kw, :label, "degree-3 polynomial"),
(:kw, :color, QuoteNode(:red)),
(:kw, :lw, 2)),
:xs, (:., :f, (:tuple, :xs)))) |> texpr2expr |>
x -> display("text/markdown", "```julia\n$x\n```")
begin
using Plots
n = 20
x = range(-π, π; length = 20)
noise = 0.3 * randn(n)
y = sin.(x) + noise
X = x .^ var"'"(0:3)
b = X \ y
f(x) = begin
evalpoly(x, b)
end
xs = range(-π, π; length = 400)
plot(; legend = :topleft)
scatter!(x, y; label = "sample")
plot!(xs, sin.(xs); label = "sin(x)", color = :blue, ls = :dash)
plot!(xs, f.(xs); label = "degree-3 polynomial", color = :red, lw = 2)
end
@doc MetaUtils
MetaUtils
contains utilities for metaprogramming in Julia.
export @show_sexpr,
show_tree, @show_tree,
print_subtypes,
show_expr, @show_expr,
show_texpr, @show_texpr,
texpr2expr, teval, @teval
@doc @show_sexpr
@show_sexpr(expr, linenums=false)
shows the lisp style S-expression of expr
and prints the line number nodes if linenums
is true. This is the macro version of Meta.show_sexpr
.
julia> @show_sexpr 2x+1
(:call, :+, (:call, :*, 2, :x), 1)
teval
function can evaluate the output of @show_sexpr
.
julia> x = 10; (:call, :+, (:call, :*, 2, :x), 1) |> teval
21
@doc @show_tree
@show_tree(expr, maxdepth=10, linenums=false)
shows the tree form of the expression expr
with maxdepth and prints the line number nodes if linenums
is true.
julia> @show_tree 2x+1
Expr(:call)
├─ :+
├─ Expr(:call)
│ ├─ :*
│ ├─ 2
│ └─ :x
└─ 1
@doc show_tree
show_tree(expr) = AbstractTrees.print_tree(expr)
can be regarded as the function version of @show_tree
.
@doc print_subtypes
print_subtypes(T::Type; kwargs...)
print_subtypes(io::IO, T::Type; kwargs...)
print_subtypes(f, io::IO, T::Type; kwargs...)
prints the subtypes of T
by AbstractTrees.print_tree
.
julia> print_subtypes(AbstractRange)
AbstractRange
├─ LinRange
├─ OrdinalRange
│ ├─ AbstractUnitRange
│ │ ├─ Base.IdentityUnitRange
│ │ ├─ Base.OneTo
│ │ ├─ Base.Slice
│ │ └─ UnitRange
│ └─ StepRange
└─ StepRangeLen
@doc show_expr
show_expr([io::IO,], ex)
shows expression ex
as a Julia style expression.
julia> show_expr(:(f(x, g(y, z))))
Expr(:call, :f, :x,
Expr(:call, :g, :y, :z))
@doc @show_expr
@show_expr(expr, linenums=false)
shows the Juia style expression of expr
and prints the line number nodes if linenums
is true. This is the macro version of show_expr
.
julia> @show_expr 2x+1
Expr(:call, :+,
Expr(:call, :*, 2, :x), 1)
eval
function can evaluate the output of @show_expr
.
julia> x = 10; Expr(:call, :+,
Expr(:call, :*, 2, :x), 1) |> eval
21
@doc show_texpr
show_texpr([io::IO,], ex)
Yet another Meta.show_sexpr
. It shows expression ex
as a lisp style expression.
Remark: The indentation is different from Meta.show_sexpr
.
julia> show_texpr(:(f(x, g(y, z))))
Expr(:call, :f, :x,
Expr(:call, :g, :y, :z))
@doc @show_texpr
@show_texpr(expr, linenums=false)
Yet another @show_sexpr
. It shows the lisp style S-expression of expr
and prints the line number nodes if linenums
is true.
Remark: The indentation is different from @show_sexpr
.
julia> @show_texpr 2x+1
(:call, :+,
(:call, :*, 2, :x), 1)
teval
function can evaluate the output of @show_texpr
.
julia> x = 10; (:call, :+,
(:call, :*, 2, :x), 1) |> teval
21
@doc teval
teval(texpr, m::Module=Main)
evaluates the lisp-like tuple expression texpr
.
Example: Calculation of sin(π/6)
julia> (:call, :sin, (:call, :/, π, 6)) |> teval
0.49999999999999994
In some cases, you can omit :call
.
julia> (:sin, (:/, π, 6)) |> teval
0.49999999999999994
@doc @teval
@teval texpr
evaluates the lisp-like tuple expression texpr
.
Example: Calculation of sin(π/6)
julia> @teval (:call, :sin, (:call, :/, π, 6))
0.49999999999999994
In some cases, you can omit :call
.
julia> @teval (:sin, (:/, π, 6))
0.49999999999999994
@doc MetaUtils.@t
MetaUtils.@t texpr
shows the Julia expression and the value of the lisp-like tuple expression texpr
.
Example:
julia> MetaUtils.@t (:call, :sin, (:call, :/, π, 6))
:(sin(π / 6))
→ 0.49999999999999994
@doc MetaUtils.@T
MetaUtils.@T texpr
shows show(texpr)
, show_texpr(texpr)
, the Julia expression, and the value of the lisp-like tuple expression texpr
.
Example:
julia> MetaUtils.@T (:call, :sin, (:call, :/, π, 6))
(:call, :sin, (:call, :/, π, 6))
→ (:call, :sin,
(:call, :/, π, 6))
→ :(sin(π / 6))
→ 0.49999999999999994