Assertion and Verbosity Macros
We describe here various macros provided by AbstractAlgebra.
Verbosity macros
There is a list of symbols called verbosity scopes which represent keywords used to trigger some particular macros within the codes. Each of these verbosity scopes is associated with a verbosity level, being set to $0$ by default. A verbosity macro is joined to a verbosity scope S
and a value k
(set to $1$ by default) such that, if the current verbosity level l
of S
is bigger than or equal to k
, then the macro triggers a given action.
AbstractAlgebra.add_verbosity_scope
— MethodAbstractAlgebra.add_verbosity_scope(s::Symbol) -> Nothing
Add the symbol s
to the list of (global) verbosity scopes.
Examples
julia> AbstractAlgebra.add_verbosity_scope(:MyScope)
-
AbstractAlgebra.set_verbosity_level
— MethodAbstractAlgebra.set_verbosity_level(s::Symbol, l::Int) -> Int
If s
represents a known verbosity scope, set the current verbosity level of s
to l
.
One can access the current verbosity level of s
by calling the function get_verbosity_level
.
If s
is not yet known as a verbosity scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of verbosity scopes by calling the function add_verbosity_scope
.
Examples
julia> AbstractAlgebra.add_verbosity_scope(:MyScope)
+
AbstractAlgebra.set_verbosity_level
— MethodAbstractAlgebra.set_verbosity_level(s::Symbol, l::Int) -> Int
If s
represents a known verbosity scope, set the current verbosity level of s
to l
.
One can access the current verbosity level of s
by calling the function get_verbosity_level
.
If s
is not yet known as a verbosity scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of verbosity scopes by calling the function add_verbosity_scope
.
Examples
julia> AbstractAlgebra.add_verbosity_scope(:MyScope)
julia> AbstractAlgebra.set_verbosity_level(:MyScope, 4)
4
julia> AbstractAlgebra.set_verbosity_level(:MyScope, 0)
-0
AbstractAlgebra.get_verbosity_level
— MethodAbstractAlgebra.get_verbosity_level(s::Symbol) -> Int
If s
represents a known verbosity scope, return the current verbosity level of s
.
One can modify the current verbosity level of s
by calling the function set_verbosity_level
.
If s
is not yet known as a verbosity scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of verbosity scopes by calling the function add_verbosity_scope
.
Examples
julia> AbstractAlgebra.add_verbosity_scope(:MyScope)
+0
AbstractAlgebra.get_verbosity_level
— MethodAbstractAlgebra.get_verbosity_level(s::Symbol) -> Int
If s
represents a known verbosity scope, return the current verbosity level of s
.
One can modify the current verbosity level of s
by calling the function set_verbosity_level
.
If s
is not yet known as a verbosity scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of verbosity scopes by calling the function add_verbosity_scope
.
Examples
julia> AbstractAlgebra.add_verbosity_scope(:MyScope)
julia> AbstractAlgebra.get_verbosity_level(:MyScope)
0
@@ -21,7 +21,7 @@
0
julia> AbstractAlgebra.get_verbosity_level(:MyScope)
-0
Printings
AbstractAlgebra.@vprintln
— Macro@vprintln(S::Symbol, k::Int, msg::String)
+0
Printings
AbstractAlgebra.@vprintln
— Macro@vprintln(S::Symbol, k::Int, msg::String)
@vprintln S k msg
@vprintln(S::Symbol, msg::String)
@@ -45,11 +45,11 @@
julia> vprint_example()
Triggered
-Triggered
If one does not setup in advance a verbosity scope, the macro will raise an ExceptionError
showing the error message "Not a valid symbol".
AbstractAlgebra.@vprint
— Macro@vprint(S::Symbol, k::Int, msg::String)
+Triggered
If one does not setup in advance a verbosity scope, the macro will raise an ExceptionError
showing the error message "Not a valid symbol".
AbstractAlgebra.@vprint
— Macro@vprint(S::Symbol, k::Int, msg::String)
@vprint S k msg
@vprint(S::Symbol, msg::String)
-@vprint S msg
The same as @vprintln
, but without the final newline.
Actions
AbstractAlgebra.@v_do
— Macro@v_do(S::Symbol, k::Int, act::Expr)
+@vprint S msg
The same as @vprintln
, but without the final newline.
Actions
AbstractAlgebra.@v_do
— Macro@v_do(S::Symbol, k::Int, act::Expr)
@v_do S k act
@v_do(S::Symbol, act::Expr)
@@ -73,14 +73,14 @@
v_do_example (generic function with 1 method)
julia> v_do_example(1,1,1,1)
-(2, 3, 1, 1)
If one does not setup in advance a verbosity scope, the macro will raise an ExceptionError
showing the error message "Not a valid symbol".
Assertion macros
There is a list of symbols called assertion scopes which represent keywords used to trigger some particular macros within the codes. Each of these assertion scopes is associated with an assertion level, being set to $0$ by default. An assertion macro is joined to an assertion scope S
and a value k
(set to $1$ by default) such that, if the current assertion level l
of S
is bigger than or equal to k
, then the macro triggers an action on the given assertion
AbstractAlgebra.add_assertion_scope
— MethodAbstractAlgebra.add_assertion_scope(s::Symbol) -> Nothing
Add the symbol s
to the list of (global) assertion scopes.
Examples
julia> AbstractAlgebra.add_assertion_scope(:MyScope)
-
AbstractAlgebra.set_assertion_level
— MethodAbstractAlgebra.set_assertion_level(s::Symbol, l::Int) -> Int
If s
represents a known assertion scope, set the current assertion level of s
to l
.
One can access the current assertion level of s
by calling the function get_assertion_level
.
If s
is not yet known as an assertion scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of assertion scopes by calling the function add_assertion_scope
.
Examples
julia> AbstractAlgebra.add_assertion_scope(:MyScope)
+(2, 3, 1, 1)
If one does not setup in advance a verbosity scope, the macro will raise an ExceptionError
showing the error message "Not a valid symbol".
Assertion macros
There is a list of symbols called assertion scopes which represent keywords used to trigger some particular macros within the codes. Each of these assertion scopes is associated with an assertion level, being set to $0$ by default. An assertion macro is joined to an assertion scope S
and a value k
(set to $1$ by default) such that, if the current assertion level l
of S
is bigger than or equal to k
, then the macro triggers an action on the given assertion
AbstractAlgebra.add_assertion_scope
— MethodAbstractAlgebra.add_assertion_scope(s::Symbol) -> Nothing
Add the symbol s
to the list of (global) assertion scopes.
Examples
julia> AbstractAlgebra.add_assertion_scope(:MyScope)
+
AbstractAlgebra.set_assertion_level
— MethodAbstractAlgebra.set_assertion_level(s::Symbol, l::Int) -> Int
If s
represents a known assertion scope, set the current assertion level of s
to l
.
One can access the current assertion level of s
by calling the function get_assertion_level
.
If s
is not yet known as an assertion scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of assertion scopes by calling the function add_assertion_scope
.
Examples
julia> AbstractAlgebra.add_assertion_scope(:MyScope)
julia> AbstractAlgebra.set_assertion_level(:MyScope, 4)
4
julia> AbstractAlgebra.set_assertion_level(:MyScope, 0)
-0
AbstractAlgebra.get_assertion_level
— MethodAbstractAlgebra.get_assertion_level(s::Symbol) -> Int
If s
represents a symbol of a known assertion scope, return the current assertion level of s
.
One can modify the current assertion level of s
by calling the function set_assertion_level
.
If s
is not yet known as an assertion scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of assertion scopes by calling the function add_assertion_scope
.
Examples
julia> AbstractAlgebra.add_assertion_scope(:MyScope)
+0
AbstractAlgebra.get_assertion_level
— MethodAbstractAlgebra.get_assertion_level(s::Symbol) -> Int
If s
represents a symbol of a known assertion scope, return the current assertion level of s
.
One can modify the current assertion level of s
by calling the function set_assertion_level
.
If s
is not yet known as an assertion scope, the function raises an ErrorException
showing the error message "Not a valid symbol". One can add s
to the list of assertion scopes by calling the function add_assertion_scope
.
Examples
julia> AbstractAlgebra.add_assertion_scope(:MyScope)
julia> AbstractAlgebra.get_assertion_level(:MyScope)
0
@@ -95,7 +95,7 @@
0
julia> AbstractAlgebra.get_assertion_level(:MyScope)
-0
Check
AbstractAlgebra.@hassert
— Macro@hassert(S::Symbol, k::Int, assert::Expr)
+0
Check
AbstractAlgebra.@hassert
— Macro@hassert(S::Symbol, k::Int, assert::Expr)
@hassert S k assert
@hassert(S::Symbol, assert::Expr)
@@ -124,7 +124,7 @@
1
julia> AbstractAlgebra.set_assertion_level(:MyScope, 0)
-0
If one does not setup in advance an assertion scope, the macro will raise an ExceptionError
showing the error message "Not a valid symbol".
Miscellaneous
AbstractAlgebra.@req
— Macro@req(assert, msg)
+0
If one does not setup in advance an assertion scope, the macro will raise an ExceptionError
showing the error message "Not a valid symbol".
Miscellaneous
AbstractAlgebra.@req
— Macro@req(assert, msg)
@req assert msg
Check whether the assertion assert
is true. If not, throw an ArgumentError
with error message msg
.
The macro @req
takes two arguments: the first one is an assertion assert
(an expression which returns a boolean) and a string msg
corresponding to the desired error message to be returned whenever assert
is false.
If the number of arguments is not 2, an AssertionError
is raised.
Examples
julia> function req_test(x::Int)
@req iseven(x) "x must be even"
return div(x,2)
@@ -140,4 +140,4 @@
catch e e
end
1
-