apply - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Operations : Operators : apply

apply

construct a function expression

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

apply(p, rest)

Parameters

p

-

expression (e.g., a procedure or name) to be applied

rest

-

(optional) expression sequence of arguments to be passed to p

Description

• 

The apply(p, rest) calling sequence returns the expression prest.

• 

Using unapply, the apply procedure satisfies the functional equation apply(unapply(p, v), op(v)) = p.

• 

If p has special evaluation rules, then these rules are not respected.

Examples

apply(g);

g

(1)

apply(f, s);

fs

(2)

apply(f, s, t, u, v);

fs,t,u,v

(3)

apply(sin, Pi);

0

(4)

map(apply, [sin, cos, tan], Pi);

0,−1,0

(5)

apply( [sin, cos, tan], Pi );

0,−1,0

(6)

apply(unapply([x^2,exp(x),x],x),2);

4,ⅇ2,2

(7)

apply(unapply(x^2 + y^2, [x, y]), a, b);

a2+b2

(8)

map(proc(n)
    description "an anonymous and recursive procedure";
        (x -> apply(x, x))(f -> proc(p, c)
                                    if c > n then
                                            p
                                    else
                                            (f(f))(p * c, 1 + c)
                                    end if
                                end proc)(1, 1)
    end proc, [$ 1 .. 10]);

1,2,6,24,120,720,5040,40320,362880,3628800

(9)

An example of special evaluation rules. The command Typesetting[Typeset] is an internal command that receives a Maple expression, and returns an expression used by the GUI for typesetting purposes. The output usually looks just like the input, but it is a very different expression:

Typesetting[Typeset](sqrt(x));

x

(10)

lprint(Typesetting[Typeset](sqrt(x)));

Typesetting:-msqrt(Typesetting:-mi("x"))

The first argument to Typeset has type uneval, signifying that it is not evaluated before being passed to Typesetting[Typeset]. In the previous example, that means we can assign something to x (say, 5), but still get a typeset square root of x rather than of 5.

x := 5;

x5

(11)

Typesetting[Typeset](sqrt(x));

x

(12)

If we want x to evaluate to 5 before typesetting occurs, we can use the apply command.

apply(Typesetting[Typeset], sqrt(x));

5

(13)

See Also

curry

eval

evalapply

function

type/appliable

type/function

unapply