Ask

Ask["key"]

is a construct for use inside AskFunction that gives the value associated with key, or interactively asks for it if it is not already known.

Ask["key"formspec]

uses formspec to define how input should be requested and interpreted.

Ask[{"key1","key2",}]

gives the values associated with all the keyi, interactively asking for any that are needed.

Ask[{"key1"->formspec1,"key2"->formspec2,}]

uses the formspeci to define how input for the keyi should be requested and interpreted.

Details

  • The first time Ask["key"] occurs in the evaluation of AskFunction[{,"key"->spec,},body], a value associated with "key" is interactively requested using the form and interpretation specified by spec. Subsequent evaluations of Ask["key"] return the stored value.
  • Ask["key"] is taken to be equivalent to Ask["key"->"String"] if it is evaluated inside an AskFunction that does not give a specification for how to ask about "key".
  • Values found for "key" using Ask["key"] can be changed through evaluation of subsequent AskAppend[] constructs and can be deleted through AskConfirm[].
  • If a specification for how to ask about a key is given in an AskFunction, it overrides any specifications given in Ask constructs it contains. If no specification is given in the AskFunction, then the specification in the first Ask to be evaluated is used.
  • Ask["key"]=value or Ask["key"]:=value can be used to set the value associated with a key inside an AskFunction, if it was not previously set.
  • Ask["key"]=. unsets the value associated with a key inside an AskFunction and effectively rewinds evaluation inside an AskFunction back to the previous point a value for "key" was requested.

Examples

open allclose all

Basic Examples  (3)

Ask for a number:

In[1]:=
Click for copyable input
Out[1]=

Collect a user's name and email:

In[1]:=
Click for copyable input
Out[1]=

Already known answers are not asked for again:

In[1]:=
Click for copyable input
Out[1]=

Generalizations & Extensions  (6)

Properties & Relations  (4)

Possible Issues  (1)

See Also

AskAppend  AskedValue  AskConfirm  AskFunction  AskDisplay  AskTemplateDisplay  AskState  Input

Introduced in 2016
(10.4)