ConfirmAssert

ConfirmAssert[test]

confirms that test is True, otherwise throwing an error to the nearest surrounding Enclose.

ConfirmAssert[test,info]

evaluates info and includes its value in the thrown error if test is not True.

ConfirmAssert[test,info,tag]

uses the specified tag for any thrown errors.

Details

Examples

open allclose all

Basic Examples  (2)

Confirm that an assertion is true:

If the assertion fails, stop evaluation and throw an error to the surrounding Enclose:

Create a function that checks its arguments:

Scope  (3)

ConfirmAssert stops evaluation and returns to the matching Enclose when it throws an error:

info is only evaluated when expr cannot be confirmed:

Create a function that calls ConfirmAssert with a tag so that it can be caught dynamically:

If no tag is given, ConfirmAssert is lexically scoped:

Applications  (1)

Print a message when a failure is detected:

Properties & Relations  (2)

ConfirmAssert can be emulated with ConfirmBy or ConfirmMatch:

ConfirmAssert[f[expr]] is effectively equivalent to ConfirmBy[expr,f] except that it returns Null instead of expr:

Possible Issues  (3)

ConfirmAssert must be given a tag or be within a lexical Enclose:

Untagged ConfirmAssert works by replacing instances of the symbol ConfirmAssert with a tagged variant:

Tagged ConfirmAssert requires an Enclose with a matching tag:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_confirmassert, organization={Wolfram Research}, title={ConfirmAssert}, year={2020}, url={https://reference.wolfram.com/language/ref/ConfirmAssert.html}, note=[Accessed: 22-November-2024 ]}