Maple Professionel
Maple Académique
Maple Edition Étudiant
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professionel
MapleSim Académique
Maple T.A. - Suite d'examens de classement
Maple T.A. MAA Placement Test Suite
Möbius - Didacticiels de mathématiques en ligne
Machine Design / Industrial Automation
Aéronautique
Ingénierie des véhicules
Robotics
Energie
System Simulation and Analysis
Model development for HIL
Modélisation du procédé pour la conception de systèmes de contrôle
Robotics/Motion Control/Mechatronics
Other Application Areas
Enseignement des mathématiques
Enseignement de l’ingénierie
Enseignement secondaire et supérieur (CPGE, BTS)
Tests et évaluations
Etudiants
Modélisation financière
Recherche opérationnelle
Calcul haute performance
Physique
Webinaires en direct
Webinaires enregistrés
Agenda des évènements
Forum MaplePrimes
Blog Maplesoft
Membres Maplesoft
Maple Ambassador Program
MapleCloud
Livres blancs techniques
Bulletin électronique
Livres Maple
Math Matters
Portail des applications
Galerie de modèles MapleSim
Cas d'Etudes Utilisateur
Exploring Engineering Fundamentals
Concepts d’enseignement avec Maple
Centre d’accueil utilisateur Maplesoft
Centre de ressources pour enseignants
Centre d’assistance aux étudiants
ModuleApply - function to apply when calling a module as if it were a command
Calling Sequence
module() export ModuleApply, ...; ... end module;
Description
If a module has an export named ModuleApply, the module name can be used as if it were a procedure name. Calling M(args) invokes M:-ModuleApply(args).
Maple's module data structure is close to the "class" concept in object oriented programming. Due to the dynamic nature of Maple, modules can also be used to represent "objects". One major difference between classes and objects are constructors. Constructors can be nicely emulated using generated modules. ModuleApply provides the ability to treat a module as a function and make it "apply'able".
Examples
Example (1)
m := module() export ModuleApply; ModuleApply := proc() print("m called with args: ", [args]); end proc; end module;
Example (2)
In this example, we create a generic function that can deal with objects that export an Evalf function.
MyEvalf := proc(f) if type(f,function) and type(op(0,f),`module`(Evalf)) then op(0,f):-Evalf(op(f)); else error "cannot evaluate %1", f; end if; end proc;
Now, create an object that returns unevaluated under certain conditions. Teach the object how to behave in specific environments (like the environment of MyEvalf).
Sine := module() export ModuleApply, Evalf; ModuleApply := proc(x) if type(x,float) then sin(x); else 'Sine'(x); end if; end proc; Evalf := proc(x) `evalf/sin`(x); end proc; end module;
With floating-point data, a number is returned, otherwise Sine returns unevaluated. This is achieved by calling the ModuleApply.
Applying MyEvalf to the unevaluated response causes MyEvalf to dispatch to the object itself to compute the value.
The Cache module implements a ModuleApply function. Using Cache as a command creates a new cache table. For example:
See Also
evalapply, module, procedure
Download Help Document