Skip to content

Instantly share code, notes, and snippets.

@matsueushi
Last active March 24, 2020 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsueushi/7bc8c28853d418012e92e85ce49985d0 to your computer and use it in GitHub Desktop.
Save matsueushi/7bc8c28853d418012e92e85ce49985d0 to your computer and use it in GitHub Desktop.

https://github.com/MikeInnes/MacroTools.jl

julia> using MacroTools

julia> ex = :(f(x) = x^2 + 3x + 4)
:(f(x) = begin
          #= REPL[2]:1 =#
          x ^ 2 + 3x + 4
      end)

julia> eval(ex)
f (generic function with 1 method)

julia> def = MacroTools.splitdef(ex)
Dict{Symbol,Any} with 5 entries:
  :name        => :f
  :args        => Any[:x]
  :kwargs      => Any[]
  :body        => quote
  :whereparams => ()

julia> def[:name]
:f

julia> def[:body]
quote
    #= REPL[2]:1 =#
    x ^ 2 + 3x + 4
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment