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
Printer:-AddPrintHandler - add a print handler to Printer module
Printer:-GetPrintHandler - get a print handler from a Printer module
Calling Sequence
Printer:-AddPrintHandler(icname=handler [,icname1=handler2,...])
Printer:-AddPrintHandler(icname [,icname2,...])
Printer:-GetPrintHandler(icname)
Parameters
Printer
-
a Printer module
icname
name; Intermediate Code name
handler
procedure; procedure to print icname numeric=nprec
Description
The procedure AddPrintHandler defines a handler procedure for the intermediate code symbol icname. The handler procedure is called to print any intermediate form expression for which icname is the zeroth operand. Note that multiple arguments of the form (or icname) may be passed in a single call to Printer:-AddPrintHandler.
To clear (that is, remove) an existing print handler for a particular intermediate code symbol icname, use the calling sequence Printer:-AddPrintHandler(icname).
A print handler procedure accepts an intermediate form expression, and issues Print statements necessary to properly print the intermediate form. A print handler procedure's return value is ignored.
The GetPrintHandler command returns the print handler procedure for the intermediate code name icname.
The module returned by DefaultPrinter has default print handlers for every intermediate code symbol. For simplicity, overriding these default definitions with AddPrintHandler should be done only if the form of the printed expression differs significantly from the form suggested by the default print handler.
Instead, include language-specific information by overriding language attributes with SetLanguageAttribute.
In some cases, the desired appearance of icname may differ significantly from what is possible with default print handlers. In these cases, AddPrintHandler should be used.
Examples
Define a custom language extending Java, which prints floating-point numbers in standard decimal notion if possible. (By default, the Java translator uses scientific notation.)
LanguageDefinition[Define]("AddPrintHandler_Example1", extend="Java", AddPrintHandler( Names:-Float = proc(mantissa, exponent) Printer:-Print( sprintf("%g", mantissa*10^exponent) ); end proc ) ); Translate(3.14159, language="Java");
cg = 0.314159e1;
cg0 = 3.14159;
Next, suppose we have a set of C functions, called addInteger, addNumeric, multiplyInteger, and multiplyNumeric, that we wish to use for integer or numeric addition or subtraction, instead of using the built-in C operators. Here we see how an extension language can be defined to achieve this.
LanguageDefinition[Define]("AddPrintHandler_Example2", extend="C", AddPrintHandler( Names:-Product = proc() local t, i; t := Printer:-GetExpressionType( Names:-Product(args) ); if t = Names:-Type('numeric') then Printer:-Print( "multiplyNumeric(" ); else Printer:-Print( "multiplyInteger(" ); end if; for i from 1 to nargs-1 do Printer:-Print( args[i], ", " ); end do; Printer:-Print( args[nargs], ")" ); end proc, Names:-Sum = proc() local t, i; t := Printer:-GetExpressionType( Names:-Sum(args) ); if t = Names:-Type('numeric') then Printer:-Print( "addNumeric(" ); else Printer:-Print( "addInteger(" ); end if; for i from 1 to nargs-1 do Printer:-Print( args[i], ", " ); end do; Printer:-Print( args[nargs], ")" ); end proc, Names:-Coercion = proc(x) Printer:-Print(x) end proc ) ); Translate( proc(x) (2*x+1)*3.5 end proc, language="AddPrintHandler_Example2");
double cg1 (int x) { return(multiplyNumeric(0.35e1, addInteger(multiplyInteger(2, x), 1))); }
See Also
DefaultPrinter, LanguageAttribute, Print, Printer
Download Help Document
Copyright © MathResources Inc. All Rights Reserved.
www.mathresources.com