using `use`

acer 29759 Maple

Large or involved projects may involve Maple modules which rely upon each other. Routines in one module may call routines in another module. Interdependence of modules can have a direct bearing on the available means of successfully utilizing the `use` functionality. In certain situations, some of the ways to utilize the `use` statement can be problematic.

Some such situations, and workarounds, are illustrated below.

The basic description of the `use` statement functionality is,

     The use statement allows you to specify local bindings
     of names, module ``imports'', and operator overriding.

See the help-page ?use for more details.

The implicit short-form version of `use` can cause difficulties. As the projects get larger these difficulties can become a burden. So, one may elect to avoid some forms of `use` in deference to other forms.

Here are some examples to illustrate the difficulties and some of their resolutions.

# Failed definition of module, due to dependency.
>
> m1 := module()
> export f1;
>   f1 := proc(x)
>     use m2 in
>       f2(x);
>     end use;
>   end proc;
> end module:
Error, `m2` is not a module or member
>
>
> restart:
>
# The explicit routine-by-routine long-form of `use` works.
>
> m1 := module()
> export f1;
>   f1 := proc(x)
>     use f2=:-m2:-f2 in
>       f2(x);
>     end use;
>   end proc;
> end module:
>
> m2 := module()
> export f2;
>   f2 := proc(x)
>       sin(x);
>   end proc;
> end module:
>
> m1:-f1(17);
                                    sin(17)
 
>
>
> restart:
>
# Reordering the procedure defns also works, for this example.
# But this may not always be possible, for very involved projects.
>
> m2 := module()
> export f2;
>   f2 := proc(x)
>       sin(x);
>   end proc;
> end module:
>
> m1 := module()
> export f1;
>   f1 := proc(x)
>     use m2 in
>       f2(x);
>     end use;
>   end proc;
> end module:
>
> m1:-f1(17);
                                    sin(17)
 
>
>
> restart:
>
# :- also works, with `use` omitted altogether, with either order.
>
> m1 := module()
> export f1;
>   f1 := proc(x)
>       m2:-f2(x);
>   end proc;
> end module:
>
> m2 := module()
> export f2;
>   f2 := proc(x)
>       sin(x);
>   end proc;
> end module:
>                                                                                 
> m1:-f1(17);
                                    sin(17)
 
>
>
> restart:
>
# Case of cyclic dependency of modules (but not of procs themselves).
# This can be problematic with either/any order of defining the procedures.
>
> m1 := module()
> export f1, f3;
>   f1 := proc(x)
>     use m2 in
>       f2(x);
>     end use;
>   end proc;
>   f3 := proc(x)
>     sin(x);
>   end proc;
> end module:
Error, `m2` is not a module or member
>
> m2 := module()
> export f2;
>   f2 := proc(x)
>     use m1 in
>       f3(x);
>     end use;
>   end proc;
> end module:
Error, `m1` is not a module or member
>
>
> restart:
>
# The explicit routine-by-routine long-form of `use` works.
>
> m1 := module()
> export f1, f3;
>   f1 := proc(x)
>     use f2=:-m2:-f2 in
>       f2(x);
>     end use;
>   end proc;
>   f3 := proc(x)
>     sin(x);
>   end proc;
> end module:
>                                                                                 
> m2 := module()
> export f2;
>   f2 := proc(x)
>     use f3=:-m1:-f3 in
>       f3(x);
>     end use;
>   end proc;
> end module:
>
> m1:-f1(17);
                                    sin(17)
 
>
>
> restart:
>
# :- without `use` also works.
>
> m1 := module()
> export f1, f3;
>   f1 := proc(x)
>       m2:-f2(x);
>   end proc;
>   f3 := proc(x)
>       sin(x);
>   end proc;
> end module:
>                                                                                 
> m2 := module()
> export f2;
>   f2 := proc(x)
>       m1:-f3(x);
>   end proc;
> end module:
>
> m1:-f1(17);
                                    sin(17)

Please Wait...