Match.MatchFailure
— TypeMatchFailure(value)
Construct an exception to be thrown when a value fails to match a pattern in the @match
macro.
diff --git a/previews/PR116/.documenter-siteinfo.json b/previews/PR116/.documenter-siteinfo.json index 0dbaa72..244376a 100644 --- a/previews/PR116/.documenter-siteinfo.json +++ b/previews/PR116/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-11-14T18:11:56","documenter_version":"1.8.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-11-15T15:10:14","documenter_version":"1.8.0"}} \ No newline at end of file diff --git a/previews/PR116/index.html b/previews/PR116/index.html index 4edd262..64be5d0 100644 --- a/previews/PR116/index.html +++ b/previews/PR116/index.html @@ -206,11 +206,11 @@ expr_type, " expression:\n", " $e\n") end -end
The following pages on pattern matching in scala provided inspiration for the library:
The following paper on pattern-matching inspired the automaton approach to code generation:
Match.MatchFailure
Match.extract
Match.match_fieldnames
Match.@__match__
Match.@ismatch
Match.@match
Match.@match_fail
Match.@match_fail
Match.@match_return
Match.@match_return
Match.MatchFailure
— TypeMatchFailure(value)
Construct an exception to be thrown when a value fails to match a pattern in the @match
macro.
Match.extract
— Methodextract(T::Type, value)
Implement extractor for type T
, returning a tuple of fields of value
, or nothing
if the match fails. This can be used to override matching on type T
. If extract(T, value)
returns a tuple, it will be used instead of the default field extraction.
Match.match_fieldnames
— Methodmatch_fieldnames(type::Type)
Return a tuple containing the ordered list of the names (as Symbols) of fields that can be matched either nominally or positionally. This list should exclude synthetic fields that are produced by packages such as Mutts and AutoHashEqualsCached. This function may be overridden by the client to hide fields that should not be matched.
Match.@__match__
— MacroUsage:
@__match__ value begin
+end
The following pages on pattern matching in scala provided inspiration for the library:
The following paper on pattern-matching inspired the automaton approach to code generation:
Match.MatchFailure
Match.extract
Match.match_fieldnames
Match.@__match__
Match.@ismatch
Match.@match
Match.@match_fail
Match.@match_fail
Match.@match_return
Match.@match_return
Match.MatchFailure
— TypeMatchFailure(value)
Construct an exception to be thrown when a value fails to match a pattern in the @match
macro.
Match.extract
— Methodextract(T::Type, value)
Implement extractor for type T
, returning a tuple of fields of value
, or nothing
if the match fails. This can be used to override matching on type T
. If extract(T, value)
returns a tuple, it will be used instead of the default field extraction.
Match.match_fieldnames
— Methodmatch_fieldnames(type::Type)
Return a tuple containing the ordered list of the names (as Symbols) of fields that can be matched either nominally or positionally. This list should exclude synthetic fields that are produced by packages such as Mutts and AutoHashEqualsCached. This function may be overridden by the client to hide fields that should not be matched.
Match.@__match__
— MacroUsage:
@__match__ value begin
pattern1 => result1
pattern2 => result2
...
- end
Return result
for the first matching pattern
. If there are no matches, throw MatchFailure
. This uses a brute-force code gen strategy, essentially a series of if-else statements. It is used for testing purposes, as a reference for correct semantics. Because it is so simple, we have confidence about its correctness.
Match.@ismatch
— Macro@ismatch value pattern
Return true
if value
matches pattern
, false
otherwise. When returning true
, binds the pattern variables in the enclosing scope.
See also @match
for the syntax of patterns
Examples
julia> struct Point
+ end
Return result
for the first matching pattern
. If there are no matches, throw MatchFailure
. This uses a brute-force code gen strategy, essentially a series of if-else statements. It is used for testing purposes, as a reference for correct semantics. Because it is so simple, we have confidence about its correctness.
Match.@ismatch
— Macro@ismatch value pattern
Return true
if value
matches pattern
, false
otherwise. When returning true
, binds the pattern variables in the enclosing scope.
See also @match
for the syntax of patterns
Examples
julia> struct Point
x
y
end
@@ -224,7 +224,7 @@
On the y axis at y = 3
Guarded patterns ought not be used with @ismatch
, as you can just use &&
instead:
julia> if (@ismatch p Point(x, y)) && x < y
println("The point (", x, ", ", y, ") is in the upper left semiplane")
end
-The point (0, 3) is in the upper left semiplane
Match.@match
— Macro@match pattern = value
+The point (0, 3) is in the upper left semiplane
Match.@match
— Macro@match pattern = value
@match value begin
pattern1 => result1
pattern2 => result2
@@ -286,7 +286,7 @@
julia> f(Foo(2, "not a foo"))
ERROR: MatchFailure(Foo(2, "not a foo"))
-...
Match.@match_fail
— Macro@match_fail
Inside the result part of a @match case, you can cause the pattern to fail (as if the pattern did not match).
Examples
julia> struct Vect
+...
Match.@match_fail
— Macro@match_fail
Inside the result part of a @match case, you can cause the pattern to fail (as if the pattern did not match).
Examples
julia> struct Vect
x
y
end
@@ -309,7 +309,7 @@
Vect(0.5547001962252291, 0.8320502943378437)
julia> norm(Vect(0, 0))
-Vect(0, 0)
Match.@match_fail
— Macro@match_fail
This statement permits early-exit from the value of a @match case. The programmer may write the value as a begin ... end
and then, within the value, the programmer may write
@match_fail
to cause the case to terminate as if its pattern had failed. This permits cases to perform some computation before deciding if the rule "really" matched.
Match.@match_return
— Macro@match_return value
Inside the result part of a @match case, you can return a given value early.
Examples
julia> struct Vect
+Vect(0, 0)
Match.@match_fail
— Macro@match_fail
This statement permits early-exit from the value of a @match case. The programmer may write the value as a begin ... end
and then, within the value, the programmer may write
@match_fail
to cause the case to terminate as if its pattern had failed. This permits cases to perform some computation before deciding if the rule "really" matched.
Match.@match_return
— Macro@match_return value
Inside the result part of a @match case, you can return a given value early.
Examples
julia> struct Vect
x
y
end
@@ -332,4 +332,4 @@
Vect(0.5547001962252291, 0.8320502943378437)
julia> norm(Vect(0, 0))
-Vect(0, 0)
Match.@match_return
— Macro@match_return value
This statement permits early-exit from the value of a @match case. The programmer may write the value as a begin ... end
and then, within the value, the programmer may write
@match_return value
to terminate the value expression early with success, with the given value.
Settings
This document was generated with Documenter.jl version 1.8.0 on Thursday 14 November 2024. Using Julia version 1.11.1.