From 2b874441ae6baea779f378dc2c8ba15ddb4ca3e7 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Wed, 12 Feb 2020 14:24:46 +0100 Subject: [PATCH] update and add docs --- docs/src/index.md | 8 ++++++-- src/OptionalArgChecks.jl | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 0b572fc..6235afe 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -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 diff --git a/src/OptionalArgChecks.jl b/src/OptionalArgChecks.jl index cca9c8a..0384ca9 100644 --- a/src/OptionalArgChecks.jl +++ b/src/OptionalArgChecks.jl @@ -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) @@ -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 ``` """ @@ -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 @@ -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)))