 Evaluate - Maple Help

Maplets[Elements]

 Evaluate
 specify command to run in Maple Calling Sequence Evaluate(opts, args) Parameters

 opts - equation(s) of the form option=value where option is one of function, option, target, or waitforresult; specify options for the Evaluate element args - (optional) Argument elements Description

 • The Evaluate command element runs a Maple procedure with the given set of arguments args in the underlying Maple session.
 • The Evaluate element features can be modified by using options.  To simplify specifying options in the Maplets package, certain options and contents can be set without using an equation. The following table lists elements, symbols, and types (in the left column) and the corresponding option or content (in the right column) to which inputs of this type are, by default, assigned.

 Elements, Symbols, or Types Assumed Option or Content x::{name, string} = y::anything target = x, function = y any other name or string source option to an Argument element

 • An Evaluate element can contain Argument elements.
 • An Evaluate element can be contained in a Maplet element; in an equation for the onapprove, oncancel, onchange, onclick, ondecline, or onstartup option for an element; or wrapped in an Action element as a parameter in an element that accepts an onchange or onclick option without an equation.
 • The following table describes the control and use of the Evaluate element options.
 An x in the I column indicates that the option can be initialized, that is, specified in the calling sequence (element definition).
 An x in the R column indicates that the option is required in the calling sequence.
 An x in the G column indicates that the option can be read, that is, retrieved by using the Get tool.
 An x in the S column indicates that the option can be written, that is, set by using the SetOption element or the Set tool.

 Option I R G S function x option x target x waitforresult x

 • The opts argument can contain one or more of the following equations that set Maplet application options.
 function = string or anything
 If the right-hand-side is of type string, it specifies the name of the procedure to be evaluated. Arguments args to the procedure specified in the right-hand-side must be included by using Argument elements. The arguments are passed in the order of the Argument element calls. For example, if there are two text fields with references $\mathrm{TF1}$ and $\mathrm{TF2}$, use:

$\mathrm{Evaluate}\left(\mathrm{function}="diff",\mathrm{Argument}\left(\mathrm{TF1}\right),\mathrm{Argument}\left(\mathrm{TF2}\right)\right)$

 to execute the command diff(TF1, TF2) in the underlying Maple session. Note that this method can only be used for global procedures (in this case diff), as the function name is specified as a string. In addition, this approach allows for a single Argument to contain multiple comma separated values, so, for example the form:

$\mathrm{Evaluate}\left(\mathrm{function}="diff",\mathrm{Argument}\left(\mathrm{TF1}\right)\right)$

 where $\mathrm{TF1}$ contains $"f\left(x\right),x"$, will have the expected result. Note that this will fail in this case if $\mathrm{TF1}$ does not contain a function and a name separated by a comma.
 If the function argument is a procedure name, or an indexed procedure name, then it is used with the arguments as specified. For example, you can use:

$\mathrm{Evaluate}\left(\mathrm{function}={'\mathrm{evalf}'}_{\mathrm{dig}},\mathrm{Argument}\left(\mathrm{TF1}\right)\right)$

 to evaluate the field $\mathrm{TF1}$ to floating point to the specified value of digits dig. Note that this method can be used to pass fixed values, determined at Maplet application creation time, to a local procedure using indexed function notation. As with the prior method, this approach also allows for a single Argument to contain multiple comma separated values. This form of evaluate is the only form that supports Argument using the value syntax, and allows passing of fixed values to the specified procedure.
 If the function argument is not of either of the prior types, Evaluate dynamically creates an internal procedure unapplied with respect to all arguments specified by using references of type name. That is, the specified expression is computed by using the value(s) of the element(s) referenced by name. Argument elements cannot be used in the Evaluate element in this case. For example, if there are two text fields with references $\mathrm{TF1}$ and $\mathrm{TF2}$, use:

$\mathrm{Evaluate}\left(\mathrm{function}='\frac{ⅆ\mathrm{TF1}}{ⅆ\mathrm{TF2}}'\right)$

 to execute the command diff(TF1, TF2) in the underlying Maple session. Note that this form can be used with a local procedure, but all arguments must be single valued. The example where you pass a single field name to diff will not work if you specify the function as 'diff(TF1)'. For more information, see unapply.
 If an argument is user-editable, for example, a text field, the user can enter an argument that is of the wrong type or does not parse correctly. It is recommended  that type checking be used by calling a Maple procedure instead of directly calling the Maple function. By using the Get function, better error handling can be implemented. For arguments that can contain only appropriate values, for example, a check box, it is better to directly pass the value because it is safe and more efficient. For example, if there is a text field and a check box with references $\mathrm{TF1}$ and $"UseCauchy"$, respectively, in the Maplet application definition, use:

$\mathrm{Evaluate}\left(\mathrm{function}='\mathrm{myproc}',\mathrm{Argument}\left("UseCauchy"\right)\right)$

 and write a procedure:

 myproc := proc(UseCauchy) expr := Maplets:-Tools:-Get( TF1::algebraic ); # expecting the text field to be an algebraic object if UseCauchy then int( expr, x, 'CauchyPrincipalValue' ); else int( expr, x ); end if; end proc;

 option = symbol
 The option of the target element to update. By default, the value option if it exists.
 target = reference to an element (name or string)
 A reference to the element to update with the result.
 waitforresult = true or false
 Whether the Maplet application waits for the Evaluate command result before running the remaining Maplet application commands in the same Action element.  By default, the value is true. Examples

 > $\mathrm{with}\left({\mathrm{Maplets}}_{\mathrm{Elements}}\right):$
 > $\mathrm{maplet}≔\mathrm{Maplet}\left(\left[\left["Enter an expression",{\mathrm{TextField}}_{'\mathrm{TF1}'}\left('\mathrm{width}'=30\right)\right],\left["Differentiate w.r.t. x:",\mathrm{Button}\left("Do It",\mathrm{Evaluate}\left('\mathrm{TF1}'='\frac{\partial }{\partial x}\mathrm{TF1}'\right)\right),\mathrm{Button}\left("OK",\mathrm{Shutdown}\left(\left['\mathrm{TF1}'\right]\right)\right)\right]\right]\right):$
 > ${\mathrm{Maplets}}_{\mathrm{Display}}\left(\mathrm{maplet}\right)$

The following three examples are identical except that the third has significantly better error handling:

 > mydiff1 := proc(f)    diff(f, x); end proc:
 > $\mathrm{maplet1}≔\mathrm{Maplet}\left(\left[\left["Enter an expression",{\mathrm{TextField}}_{'\mathrm{TF1}'}\left('\mathrm{width}'=30\right)\right],\left["Differentiate w.r.t. x:",\mathrm{Button}\left("Do It",\mathrm{Evaluate}\left('\mathrm{TF1}'='\mathrm{mydiff1}\left(\mathrm{TF1}\right)'\right)\right),\mathrm{Button}\left("OK",\mathrm{Shutdown}\left(\left['\mathrm{TF1}'\right]\right)\right)\right]\right]\right):$
 > ${\mathrm{Maplets}}_{\mathrm{Display}}\left(\mathrm{maplet1}\right)$
 > $\mathrm{maplet2}≔\mathrm{Maplet}\left(\left[\left["Enter an expression",{\mathrm{TextField}}_{'\mathrm{TF1}'}\left('\mathrm{width}'=30\right)\right],\left["Differentiate w.r.t. x:",\mathrm{Button}\left("Do It",\mathrm{Evaluate}\left('\mathrm{TF1}'="mydiff1",\mathrm{Argument}\left('\mathrm{TF1}'\right)\right)\right),\mathrm{Button}\left("OK",\mathrm{Shutdown}\left(\left['\mathrm{TF1}'\right]\right)\right)\right]\right]\right):$
 > ${\mathrm{Maplets}}_{\mathrm{Display}}\left(\mathrm{maplet2}\right)$
 > mydiff3 := proc()     f := Maplets[Tools][Get]('TF1'::algebraic);    diff(f, x); end proc: maplet3 := Maplet([    ["Enter an expression", TextField['TF1']('width' = 30)],    [       "Differentiate w.r.t. x:",       Button("Do It", Evaluate('TF1' = "mydiff3", Argument('TF1'))),       Button("OK", Shutdown(['TF1']))    ] ]): Maplets[Display](maplet3);

This is a duplicate of the first example, where the Argument element is used with value syntax:

 > $\mathrm{maplet4}≔\mathrm{Maplet}\left(\left[\left["Enter an expression",{\mathrm{TextField}}_{'\mathrm{TF1}'}\left('\mathrm{width}'=30\right)\right],\left["Differentiate w.r.t. x:",\mathrm{Button}\left("Do It",\mathrm{Evaluate}\left('\mathrm{target}'='\mathrm{TF1}','\mathrm{function}'='\mathrm{diff}',\mathrm{Argument}\left('\mathrm{TF1}'\right),\mathrm{Argument}\left('\mathrm{value}'=x\right)\right)\right),\mathrm{Button}\left("OK",\mathrm{Shutdown}\left(\left['\mathrm{TF1}'\right]\right)\right)\right]\right]\right):$
 > ${\mathrm{Maplets}}_{\mathrm{Display}}\left(\mathrm{maplet4}\right)$