Maple für Professional
Maple für Akademiker
Maple für Studenten
Maple Personal Edition
Maple Player
Maple Player für iPad
MapleSim für Professional
MapleSim für Akademiker
Maple T.A. - Testen & beurteilen
Maple T.A. MAA Placement Test Suite
Möbius - Online-Courseware
Machine Design / Industrial Automation
Luft- und Raumfahrt
Fahrzeugtechnik
Robotics
Energiebranche
System Simulation and Analysis
Model development for HIL
Anlagenmodelle für den Regelungsentwurf
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematikausbildung
Technik
Allgemein- und berufsbildende Schulen
Testen und beurteilen
Studierende
Finanzmodelle
Betriebsforschung
Hochleistungsrechnen
Physik
Live-Webinare
Aufgezeichnete Webinare
Geplante Veranstaltungen
MaplePrimes
Maplesoft-Blog
Maplesoft-Mitgliedschaft
Maple Ambassador Program
MapleCloud
Technische Whitepapers
E-Mail Newsletters
Maple-Bücher
Math Matters
Anwendungs-Center
MapleSim Modell-Galerie
Anwenderberichte
Exploring Engineering Fundamentals
Lehrkonzepte mit Maple
Maplesoft Welcome-Center
Resource-Center für Lehrer
Help-Center für Studierende
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