I know how to use the option as an argument to a function, we can define an option by using Options[]and SetOptions[], but the following usage confused me by passing a function as an option to a function .Here are two examples:

1 Answer
1

Short answer:

You supply a pure function to an option when you want to override the built-in options. In this case, "Diamond" and 0.2 resolve to certain functions or are used as values in certain functions internally which is then used for the respective option. The short names are merely a convenient way for you to remember and enter the option.

Longer answer:

It might help to understand what is done internally, so consider this simple example. We construct a function f that takes in a numeric argument x, and an optional value p (with default value 1) and we raise x to power p:

You have now built a definition for f that can take simple options for p both as "square" or as 2, which gives you additional flexibility.

Extending the idea to a function that accepts functions as option values. I'll define a function g, taking inputs as g[x, p -> func], returning func[x] and also let it take arguments as g[x, p -> "string"] for some values of "string"

Suppose you get bored of the vanilla pre-defined options and want to fancy it up, you can do that by supplying your own pure function as an option to p. For example:

Plot[g[x, p -> (Sin[Exp[#]] &)], {x, 0, π}]

By now, you can begin to see how this is useful. If you had a complicated function that needed to be input as an option or is used repeatedly, you'd want to make things simple for the end user (most likely yourself) and so you pre-define it and provide a short form that is easy to remember and conveys the intent without ambiguity. Any time this needs to be overridden (possibly for a one time use case), you can supply your own function.

Also read this answer for why you need to wrap your custom pure functions in parentheses when supplying as an option value.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.