ArgumentsOptions[f[args],n]
tries to separate args into a list of n positional arguments followed by a list of valid options for f.
ArgumentsOptions[f[args],{min,max}]
requires the number of positional arguments to be between min and max.
ArgumentsOptions[f[args],spec,assoc]
modifies the behavior based on the information in the association assoc.
ArgumentsOptions
ArgumentsOptions[f[args],n]
tries to separate args into a list of n positional arguments followed by a list of valid options for f.
ArgumentsOptions[f[args],{min,max}]
requires the number of positional arguments to be between min and max.
ArgumentsOptions[f[args],spec,assoc]
modifies the behavior based on the information in the association assoc.
Details
- ArgumentsOptions issues appropriate messages for f and returns a Failure object if f[…] has the wrong number of positional arguments, unknown options or invalid option specifications.
- The following keys can be used for the association assoc:
-
"ExtraOptions" {} additional options to treat as known options for f "OptionsMode" "Longest" how to interpret the optional positional arguments of args "Head" List wrapper for the positional arguments and options lists - Additional options given to "ExtraOptions" can be specified as rules nameval or as symbols func, which is equivalent to Options[func].
- ArgumentsOptions checks whether all options specified for f have valid names.
- The following values of "OptionsMode" can be used: »
-
"Longest" treat all trailing elements of args matching OptionsPattern[] as options for f "Shortest" treat anything other than one or more known options as positional arguments None treat all elements as positional arguments - Even with "OptionsMode""Shortest", an unknown option past position max still generates a message. »
- ArgumentsOptions has the attribute HoldFirst.
Examples
open all close allBasic Examples (1)
Declare the options of the function f:
Options[f] = {a -> 1}Separate the arguments to f into exactly one positional argument and options:
ArgumentsOptions[f[1, a -> 0], 1]Appropriate messages are issued if the arguments to f are invalid:
ArgumentsOptions[f[1, 2], 1]Scope (7)
Separate the positional arguments and options for a function that takes between 1 and 3 positional arguments:
Options[f] = {a -> 1}ArgumentsOptions[f[1, 2, a -> 3], {1, 3}]Require at least 2 positional arguments:
ArgumentsOptions[f[1, 2, 3], {2, ∞}]Calling f with 1 argument is invalid:
ArgumentsOptions[f[1], {2, ∞}]Require exactly 3 positional arguments:
Options[f] = {a -> 1, b -> 2}ArgumentsOptions[f[1, 2, 3, a -> 0, b -> 0], 3]Allow "hidden" options that do not appear in Options[f]:
ArgumentsOptions[f[1, a -> 0], 1, <|"ExtraOptions" -> {a -> 1}|>]The option a0 is not a known option for f:
Options[f]Allow the option named hidden as well as any option of Graphics to be set:
Options[f] = {normal -> Automatic}ArgumentsOptions[f[1, normal -> 3, hidden -> 2, AspectRatio -> 1], {1, 2}, <|"ExtraOptions" -> {hidden -> 0, Graphics}|>]Treat unknown trailing options in positions min+1 though max as positional arguments rather than options for f:
Options[f] = {a -> 1}The rule b1 is treated as a positional argument:
ArgumentsOptions[f[1, b -> 2, a -> 3], {1, 2}, <|"OptionsMode" -> "Shortest"|>]With the default "OptionsMode""Longest", a message is issued for unknown options:
ArgumentsOptions[f[1, b -> 2, a -> 3], {1, 2}, <|"OptionsMode" -> "Longest"|>]A known option is still treated as an option for f with "OptionsMode""Shortest":
ArgumentsOptions[f[1, a -> 2], {1, 2}, <|"OptionsMode" -> "Shortest"|>]Treat all elements as positional arguments rather than options for f:
ArgumentsOptions[f[1, a -> 2], {1, 2}, <|"OptionsMode" -> None|>]Separate the arguments without evaluating them:
ArgumentsOptions[f[2 + 2, 3 * 3, a -> 4 ^ 4], 2, <|"Head" -> Hold, "ExtraOptions" -> {a -> 0}|>]Applications (2)
Define a function that calls a helper function if called with one or two positional arguments:
Options[f] = {a -> 1}f[args___] := Block[{sep},
sep = ArgumentsOptions[f[args], {1, 2}];
g[sep] /; !FailureQ[sep]
]g[{argList_, optList_}] := Switch[Length[argList],
1, First[argList] + OptionValue[f, optList, a],
2, argList + OptionValue[f, optList, a]
]When called with one or two positional arguments, the helper function is called:
f[3, a -> 4]f[3, 4, a -> 5]When called with more than two positional arguments, f returns unevaluated and issues a message:
f[1, 2, 3]Use "OptionsMode""Shortest" to treat trailing empty lists as positional arguments:
Options[f] = {a -> b}ArgumentsOptions[f[a, {}, {}, {}], {1, 3}, <|"OptionsMode" -> "Shortest"|>]Properties & Relations (10)
ArgumentsOptions[f[…],…] issues a message and returns Failure[…] for invalid input to f:
Options[f] = {a -> 1}ArgumentsOptions[f[1, 2], 3]ArgumentsOptions[f[0, b -> 2], 1]If f does not accept options, all arguments are assumed to be positional:
Options[f]ArgumentsOptions[f[0, b -> 2], {1, 2}]Options are always returned as a flat list, irrespective of how they appeared in the input expression:
Options[f] = {a -> 1, b -> 2, c -> 3}ArgumentsOptions[f[x, a -> 0, {b -> 5, {{c -> 17}}}], 1]ArgumentsOptions[…,{min,max}] will always treat the first min arguments as positional:
Options[f] = {a -> 1}Here, even though a0 matches OptionsPattern[], it is treated as a positional argument:
ArgumentsOptions[f[1, a -> 0], {2, 3}]If the rule a0 is given after the positional arguments, it is treated as an option:
ArgumentsOptions[f[1, 2, a -> 0], {2, 3}]Only trailing options are considered when collecting options:
Options[f] = {a -> 1, b -> 2, c -> 3}ArgumentsOptions[f[x, a -> 5, y, b -> 7, c -> 11], {1, 4}]Trailing rules matching OptionsPattern[] are treated as options if they are known options for f:
Options[f] = {a -> 1, b -> 2}This is true even if "OptionsMode""Shortest" is given:
ArgumentsOptions[f[1, a -> 0, b -> 0], {1, 2}, <|"OptionsMode" -> "Shortest"|>]An option specification that contains both known and unknown options generates a message:
Options[f] = {a -> 1}ArgumentsOptions[f[1, {a -> 2, b -> 3}], 1]In "OptionsMode""Shortest", a list with known and unknown options is treated as a positional argument if possible:
Options[f] = {a -> 1}ArgumentsOptions[f[1, {a -> 2, b -> 3}], {1, 2}, <|"OptionsMode" -> "Shortest"|>]An unknown option past the maximum number of positional arguments still generates a message:
ArgumentsOptions[f[1, 2, {a -> 2, b -> 3}], {1, 2}, <|"OptionsMode" -> "Shortest"|>]Only rules matching OptionsPattern[] can be valid option specifications:
Options[f] = {a -> 1}The rule 12 does not match OptionsPattern[]:
MatchQ[1 -> 2, OptionsPattern[]]Thus it is treated as a positional argument:
ArgumentsOptions[f[1 -> 2], {0, 1}]If 12 is given after the positional arguments, it is treated as an invalid option specification:
ArgumentsOptions[f[0, 1 -> 2], {0, 1}]ArgumentsOptions returns Failure[…] when CheckArguments returns False:
ArgumentsOptions[f[], 1]CheckArguments[f[], 1]Possible Issues (3)
If f accepts options, trailing empty lists are ignored by default because {} matches OptionsPattern[]:
Options[f] = {a -> 1}ArgumentsOptions[f[1, 2, {}], {2, 3}]Use "OptionsMode""Shortest" to treat a trailing empty list as a positional argument:
ArgumentsOptions[f[1, 2, {}], {2, 3}, <|"OptionsMode" -> "Shortest"|>]All arguments at or before the minimum argument count are considered positional arguments:
ArgumentsOptions[StringCases["str", IgnoreCase -> True, Overlaps -> True], {2, 3}]ArgumentsOptions does not check whether the option values are correct:
ArgumentsOptions[Map[f, x, Heads -> ∞], {2, 3}]Infinity is not a valid value for Heads:
Map[f, x, Heads -> ∞]See Also
Tech Notes
Related Guides
Related Workflows
- Define a Function with Options
Text
Wolfram Research (2020), ArgumentsOptions, Wolfram Language function, https://reference.wolfram.com/language/ref/ArgumentsOptions.html (updated 2024).
CMS
Wolfram Language. 2020. "ArgumentsOptions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/ArgumentsOptions.html.
APA
Wolfram Language. (2020). ArgumentsOptions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArgumentsOptions.html
BibTeX
@misc{reference.wolfram_2026_argumentsoptions, author="Wolfram Research", title="{ArgumentsOptions}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ArgumentsOptions.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_argumentsoptions, organization={Wolfram Research}, title={ArgumentsOptions}, year={2024}, url={https://reference.wolfram.com/language/ref/ArgumentsOptions.html}, note=[Accessed: 12-June-2026]}