OptionalElement

OptionalElement[patt]

is a grammar rules pattern object that represents 0 or 1 instances of patt.

OptionalElement[patt,default]

uses default if the element is not present.

Details

Examples

open allclose all

Basic Examples  (2)

Allow certain words to be optional:

Supply a default value for a missing element:

Possible Issues  (1)

The default value evaluates immediately:

Use a sentinel for a dynamic default value:

Wolfram Research (2015), OptionalElement, Wolfram Language function, https://reference.wolfram.com/language/ref/OptionalElement.html.

Text

Wolfram Research (2015), OptionalElement, Wolfram Language function, https://reference.wolfram.com/language/ref/OptionalElement.html.

CMS

Wolfram Language. 2015. "OptionalElement." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/OptionalElement.html.

APA

Wolfram Language. (2015). OptionalElement. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OptionalElement.html

BibTeX

@misc{reference.wolfram_2024_optionalelement, author="Wolfram Research", title="{OptionalElement}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/OptionalElement.html}", note=[Accessed: 14-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_optionalelement, organization={Wolfram Research}, title={OptionalElement}, year={2015}, url={https://reference.wolfram.com/language/ref/OptionalElement.html}, note=[Accessed: 14-November-2024 ]}