bless – bless a function as belonging to a MuPAD domain

bless(f, mydomain) blesses the function f as belonging to the MuPAD domain mydomain

→ Examples

Call:

bless(f, mydomain)

Parameters:

f

a MuPAD function

mydomain

a MuPAD domain

Return Value:

a copy of f, as a member of the domain mydomain

Details:

Example 1:

We create a domain, with a power function, and a function curry which returns a specialization of this function for a given n. Of course, this simple example is artificial, but this kind of situation appears naturally when generating code on the fly:

domain mydomain

    power := (n,x) -> x^n;

    curry :=

    proc(n)

        option escape;

    begin

        x -> dom::power(n,x)

    end_proc;

end_domain:

power2 := mydomain::curry(2):

power2(3)

math

While this code works as written with MuPAD 3.0 (it does not work with 2.5.3 and earlier, which had slightly different rules for “inheriting” dom), the following code requires bless, since dom is not set automatically for the functions inside the table:

domain mydomain3

    new :=

    proc(x)

    begin

        if contains(dom::newFunctions, domtype(x)) then

           dom::newFunctions[domtype(x)](x);

        else

           error("Don't know how to convert x");

        end_if;

    end_proc;

 

     newFunctions :=

    map(table(

              DOM_INT  = (n -> new(dom, [$1..n])),

              DOM_LIST = (l -> new(dom, l))

             ),

        prog::bless, dom);

end_domain:

mydomain3(3);

mydomain3([1,2,3])

math

math