AskFunction

AskFunction[body]

evaluates body, interactively asking for values specified by Ask[] and related constructs.

AskFunction[{"key1"spec1,"key2"spec2,},body]

specifies how values associated with the keyi should be asked for.

Details and Options

  • The following special constructs can appear in the body of an AskFunction:
  • Ask[]ask for the value of a key if not already known
    AskedValue[]get the value of a key if it is known
    AskAppend[]ask for a value and append it to the list of known values
    AskConfirm[]confirm or change a value
    AskDisplay[]display an expression with asked values inserted
    AskTemplateDisplay[]display a template applied to the asked values
    AskedQ[]test if the value of a key has been asked for
  • AskFunction[][] evaluates in a notebook, displaying a form every time it encounters a construct that requires asking for a value.
  • CloudDeploy[AskFunction[]] yields a CloudObject corresponding to an active version of the AskFunction.
  • AskFunction[][<|"keyk"->inputk|>] represents an AskFunction where the value associated with "keyk" is taken to be inputk.

Examples

open allclose all

Basic Examples  (1)

Set up an AskFunction:

Activate it and fill in the inputs:

Or deploy it to the cloud:

You can programmatically provide known values:

Now only the second question will be asked:

Scope  (3)

Provide a first argument to AskFunction to specify how to ask for values:

AskFunction uses the evaluation semantics of the Wolfram Language to skip the questions that are not needed:

Selecting No skips the question about the spouse name:

Use the same syntax as FormFunction and FormObject to specify the appearance of the questions:

Properties & Relations  (7)

Use AskFunction in conjunction with Ask for simple questions or to get the value associated with a key:

AskConfirm can be used to rewind the evaluation to the point before a value was known:

Use AskAppend to accumulate inputs:

Use AskDisplay to display messages:

AskTemplateDisplay takes a function or a template to be applied to the current values:

Use AskedQ to verify if a key has been asked:

AskedValue returns the value without causing a form to be displayed:

Possible Issues  (1)

When AskFunction is deployed in the cloud, the body is reevaluated at each visit on a clean kernel. Because of this, functions that return random values might return different values at each step:

A possible workaround is using SeedRandom to initialize the pseudorandom number generator with a seed that depends on previous values or on values such as $RequesterAddress:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_askfunction, organization={Wolfram Research}, title={AskFunction}, year={2016}, url={https://reference.wolfram.com/language/ref/AskFunction.html}, note=[Accessed: 21-November-2024 ]}