Examples
Basic Examples (2)
Construct a name-value pattern with one required argument and two optional ones:
Use NameValuePattern as any other pattern with functions like MatchQ or Replace:
Scope (6)
Use head patterns:
Arguments with no default values bind to Sequence[]:
Rule can be used instead of Optional (:) to specify optional arguments:
RuleDelayed can be used to delay default values:
NameValuePattern matches the longest sequence:
Bind to NameValuePattern as a sequence of arguments:
Applications (1)
Define a function with flexible control over its arguments:
Properties and Relations (3)
NameValuePattern can be used as an alternative to OptionsPattern:
But it also allows specifying required arguments by name and in any order:
It can also be used at any depth:
Possible Issues (3)
If an argument is a rule with its left-hand-side not being a valid name then it's considered as a literal rule:
If an unnamed argument is provided after a named argument then rules can also be interpreted literally:
If multiple values are given for the same name, then it's not a valid match:
Neat Examples (1)
All of the expressions here match the same pattern with bindings of symbols to their corresponding defaults:
Related Links
Requirements
Wolfram Language 13.0
(December 2021) or above
Version History
-
1.0.1
– 12 September 2023
-
1.0.0
– 30 August 2023
Related Resources