# Naming arguments in Wolfram functions?

Sometimes you have functions with very long argument lists:

f[a_, b_, c_, d_, e_] := c


so is there a way to "name" these arguments (order insensitive) so that users can know what they're getting more easily? In pseudo-code:

f[c = "what I'm getting", a = 1, b = 2, d = 0, e = 1]


This is similar to "record syntax" in other programming languages.

• This is precisely what options management does. You end up with f["WhatImGetting" -> 5, "TheMainThing" -> 8, "SomethingElse" -> 77] as usual with options. – Roman Jun 27 '19 at 17:42
• @MassDefect Your link doesn't work. – George Jun 27 '19 at 18:17
• Oops, thanks for letting me know. I don't know how I managed to copy it like that. This is the one I was thinking of: reference.wolfram.com/language/tutorial/… – MassDefect Jun 27 '19 at 18:59
• You could define f to work with associations too. – Kuba Jun 28 '19 at 8:31

Here's an example for how to combine Options, OptionsPattern, and OptionValue:

First, define the available options for f and their default values:

Options[f] = {"TheMainOption" -> 0,
"SomeOtherOption" -> 7,
"TheLetter" -> "A"};


Then, define the function f (here: make a list of all option values, in a particular order that is independent of the order in which the user specifies the options in the function call):

f[OptionsPattern[]] := {OptionValue["TheMainOption"],
OptionValue["SomeOtherOption"],
OptionValue["TheLetter"]}


Note that by default, OptionsPattern[] looks up the available options and defaults from the associated definition of Options[f].

Tests: the options can be given in any order, and default values are provided in the definition of Options[f]:

f[]
(*    {0, 7, "A"}    *)

f["TheLetter" -> "Z"]
(*    {0, 7, "Z"}    *)

f["TheLetter" -> "N", "SomeOtherOption" -> -2]
(*    {0, -2, "N"}    *)


Remind me what the options and defaults were for f?

Options[f]
(*    {"TheMainOption" -> 0, "SomeOtherOption" -> 7, "TheLetter" -> "A"}    *)