Skip to content

Commit

Permalink
update and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub committed Feb 12, 2020
1 parent 0d0aeda commit 2b87444
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 6 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ CurrentModule = OptionalArgChecks

# OptionalArgChecks

Provides two macros, [`@argcheck`](@ref) and [`@skipargcheck`](@ref) which give users
control over whether to skip argument checking for better performance.
Provides two macros, [`@mark`](@ref) and [`@elide`](@ref) which give users control over
skipping arbitrary code in functions for better performance.

For convenience, this package also exports [`@argcheck`](@ref) and [`@check`](@ref) from
the package [`ArgCheck.jl`](https://github.com/jw3126/ArgCheck.jl) and provides the macro
`@skipargcheck` to skip these checks.

## API

Expand Down
16 changes: 11 additions & 5 deletions src/OptionalArgChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export @argcheck, @check
@mark label ex
Marks `ex` as an optional argument check, so when a function is called via
[`@skipargcheck`](@ref), `ex` will be omitted.
[`@elide`](@ref) with label `label`, `ex` will be omitted.
```jldoctest
julia> function half(x::Integer)
@mark argcheck iseven(x) || throw(DomainError(x, "x has to be an even number"))
@mark check_even iseven(x) || throw(DomainError(x, "x has to be an even number"))
return x ÷ 2
end
half (generic function with 1 method)
Expand All @@ -30,7 +30,7 @@ ERROR: DomainError with 3:
x has to be an even number
[...]
julia> @skipargcheck half(3)
julia> @elide check_even half(3)
1
```
"""
Expand Down Expand Up @@ -83,6 +83,12 @@ end
return ir
end

"""
@elide label ex
For every function call in `ex`, expressions marked with label `label` using the macro
[`@mark`](@ref) get omitted recursively.
"""
macro elide(label, ex)
label isa Symbol || error("label has to be a Symbol")
ex = postwalk(ex) do x
Expand All @@ -101,8 +107,8 @@ end
"""
@skipargcheck ex
For every function call in `ex`, expressions wrapped in [`@argcheck`](@ref) get omitted
recursively.
Elides argument checks created with [`@argcheck`](@ref) or [`@check`](@ref), provided by the
package `ArgCheck.jl`. Is equivalent to `@elide argcheck ex`.
"""
macro skipargcheck(ex)
return :(@elide argcheck $(esc(ex)))
Expand Down

0 comments on commit 2b87444

Please sign in to comment.