 hasoption - Maple Help

hasoption

select an option from a list/set of options Calling Sequence hasoption(L, x, 'v', 'N') hasoption(L, x=t, 'v', 'N') Parameters

 L - list of equations - the options x - name of an option v, N - (optional) names to be assigned results t - (optional) a type Description

 • The purpose of the hasoption command is to test whether a list of options, input in the form of a list of equations, for example, $\left[\mathrm{color}=\mathrm{red},\mathrm{numpoints}=99\right]$ has a given option, and to select the corresponding value.  This function is intended to help in the writing of programs which must process optional arguments.
 • The hasoption command is a boolean function. It returns true if the list of equations L contains x on the left-hand side of one equation, false otherwise. Note, inside a program, the names of options should be quoted. Hence the normal usage in a program of this command is

 if hasoption(opts,'numpoints', ...) then ... else ... end if;

 • If the third argument v is given, it is assigned the right-hand side (the value of the option) of the last equation in L with x on the left-hand side.  If the fourth argument N is specified, it is assigned a list of equations which are remaining options after removing those matching x.
 • The second form of the hasoption command has the same functionality as the first form except in addition, the right-hand side(s) of any equation with x on the left-hand side is tested to be of type t. If it is not of type t, an error is generated.
 • The hasoption command is limited to options which are equations of the form name = value, for example, $\mathrm{numpoints}=99$, and color = red.  To allow different spellings, synonyms, and abbreviations to be used for the name of an option, for example, to allow the user to input also colour = red, the second argument of the hasoption command, namely x, may be a name or set of names.  Thus you can write

 if hasoption(opts,{'color','colour'}, ...) then ... else ... end if;

 • In general, it is recommended that you use the ProcessOptions command instead of the hasoption command. Examples

 > $\mathrm{Options}≔\left[\mathrm{title}=\mathrm{sin}\left(wx\right),\mathrm{numpoints}=99,\mathrm{style}=\mathrm{POINT},\mathrm{color}=\mathrm{red}\right]$
 ${\mathrm{Options}}{≔}\left[{\mathrm{title}}{=}{\mathrm{sin}}{}\left({w}{}{x}\right){,}{\mathrm{numpoints}}{=}{99}{,}{\mathrm{style}}{=}{\mathrm{POINT}}{,}{\mathrm{color}}{=}{\mathrm{red}}\right]$ (1)
 > $\mathrm{hasoption}\left(\mathrm{Options},'\mathrm{style}','s','\mathrm{Options}'\right)$
 ${\mathrm{true}}$ (2)
 > $s$
 ${\mathrm{POINT}}$ (3)
 > $\mathrm{Options}$
 $\left[{\mathrm{title}}{=}{\mathrm{sin}}{}\left({w}{}{x}\right){,}{\mathrm{numpoints}}{=}{99}{,}{\mathrm{color}}{=}{\mathrm{red}}\right]$ (4)
 > $\mathrm{hasoption}\left(\mathrm{Options},'\mathrm{numpoints}'=\mathrm{posint},'n','\mathrm{Options}'\right)$
 ${\mathrm{true}}$ (5)
 > $n$
 ${99}$ (6)
 > $\mathrm{hasoption}\left(\mathrm{Options},\left\{'\mathrm{color}','\mathrm{colour}'\right\},'c','\mathrm{Options}'\right)$
 ${\mathrm{false}}$ (7)
 > $c$
 ${c}$ (8)
 > $\mathrm{Options}$
 $\left[{\mathrm{title}}{=}{\mathrm{sin}}{}\left({w}{}{x}\right){,}{\mathrm{color}}{=}{\mathrm{red}}\right]$ (9)
 > $\mathrm{hasoption}\left(\mathrm{Options},'\mathrm{title}'=\mathrm{string},'t','\mathrm{Options}'\right)$
 > $\mathrm{Options}$
 $\left[{\mathrm{title}}{=}{\mathrm{sin}}{}\left({w}{}{x}\right){,}{\mathrm{color}}{=}{\mathrm{red}}\right]$ (10)