Skip to content

Commit

Permalink
add signature to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Apr 9, 2020
1 parent 5c84f74 commit 99a07e7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ This package aims to provide light-weight performant tooling without requiring a

Alternatively see the [MacroTools](https://github.com/MikeInnes/MacroTools.jl) package for more powerful set of tools.

Currently, this package provides the `splitdef` and `combinedef` functions which are useful for inspecting and manipulating function definition expressions.
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 a `Dict` of its parts.
- `signature` works on a `Method` returning a similar `Dict` that holds the parts of the expressions that would form its signature.
- `combinedef` takes such `Dict` and builds it back into an expression

e.g.
```julia
Expand Down Expand Up @@ -40,6 +43,18 @@ julia> def[:head] = :(=);

julia> def[:body] = :(x * y);

julia> combinedef(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> signature(g_method)
Dict{Symbol,Any} with 3 entries:
:name => :g
:args => Expr[:(x::T), :(y::T)]
:whereparams => Any[:T]
```
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ CurrentModule = ExprTools
```@docs
splitdef
combinedef
signature
```
27 changes: 24 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ This package aims to provide light-weight performant tooling without requiring a

Alternatively see the [MacroTools](https://github.com/MikeInnes/MacroTools.jl) package for more powerful set of tools.

Currently, this package provides the `splitdef` and `combinedef` functions which are useful for inspecting and manipulating function definition expressions.

ExprTools provides tooling for working with Julia expressions during [metaprogramming](https://docs.julialang.org/en/v1/manual/metaprogramming/).
This package aims to provide light-weight performant tooling without requiring additional package dependencies.

Alternatively see the [MacroTools](https://github.com/MikeInnes/MacroTools.jl) package for 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`](@ref) works on a function definition expression and returns a `Dict` of its parts.
- [`signature`](@ref) works on a `Method` returning a similar `Dict` that holds the parts of the expressions that would form its signature.
- [`combinedef`](@ref) takes such `Dict` and builds it back into an expression

e.g.
```jldoctest
Expand Down Expand Up @@ -35,6 +44,18 @@ julia> def[:head] = :(=);
julia> def[:body] = :(x * y);
julia> combinedef(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> signature(g_method)
Dict{Symbol,Any} with 3 entries:
:name => :g
:args => Expr[:(x::T), :(y::T)]
:whereparams => Any[:T]
```
5 changes: 1 addition & 4 deletions src/type_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
Extracts the type-parameters of the `type`.
```jldoctest
julia> parameters(Foo{A, B, C}) == [A, B, C]
true
```
e.g. `parameters(Foo{A, B, C}) == [A, B, C]`
"""
parameters(sig::UnionAll) = parameters(sig.body)
parameters(sig::DataType) = sig.parameters

0 comments on commit 99a07e7

Please sign in to comment.