Language and Programming - Maple Programming Help

 Language and Programming

Maple 2020 includes the following enhancements to the Maple language and programming facilities.

Improvements to Execution Tracing

 • The tracelast command can now "see" past caught-and-rethrown exceptions. When an exception is caught and rethrown (by an error statement in a catch clause), the error is reported as having occurred in the procedure containing the catch clause. However, the stack trace produced by tracelast will now include all execution levels down to where the error originally occurred.
 • If source code for traced procedures is available and kernelopts(keepdebuginfo) is true, then kernelopts(tracelineinfo=N), where N is 0, 1, or 2, controls the display of source file and line number information in the output produced by trace or printlevel:
 • With kernelopts(tracelineinfo=0), source file and line number information is not displayed.
 • With kernelopts(tracelineinfo=1), which is the default, source file and line number information is displayed for procedure entry and exit only.
 • With kernelopts(tracelineinfo=2), source file and line number information is displayed for procedure entry and exit, as well as all other statements for which tracing output would be produced.
 • The output of the tracelast command will also show source file and line number information when kernelopts(tracelineinfo) is 1 or 2.

New Debugger Commands

 • A new debugger command, help, displays a concise summary of all the debugger commands and their options. The command can be followed by an optional topic to display only the subset of commands pertaining to the topic (e.g. help stop).
 • Executing help gdb in the debugger will display a cross reference from GNU debugger to Maple debugger commands.
 • The new retstep command is similar to the existing return command, except that execution stops at any statement executed after the current procedure returns, instead of the next statement executed in the calling procedure. This can be used, for example, while debugging expressions such as f(g(x)) or seq(f(i),i=1..10), to continue debugging procedure f after having stopped in procedure g.

Additional Information in Error and Warning Messages

 • Most error and warning messages now display the source file name and line number of the statement in which the error occurred, assuming the source code is available and kernelopts(keepdebuginfo) is true.

Additions to the Java OpenMaple API

The Java OpenMaple Application Program Interface has been extended to simplify access to Maple data structures from Java.

Many OpenMaple classes corresponding to Maple data structures now implement standard interfaces from the java.util package, which enables simpler syntax and easier integration with existing Java code making use of these interfaces. These improved classes include:

 • The OpenMaple Java List and OpenMaple Java Expseq classes, which now implement the java.util.List interface.
 • The OpenMaple Java Set class, which now implements the java.util.Set interface.
 • The OpenMaple Java Table class, which now implements the java.util.Map interface.

In particular, these interfaces enable you to easily iterate over Maple data structures in Java code using Java for-in loops.  The following sample code illustrates traversals which implicitly use these interfaces.

When compiled and executed with a Maple instance, the above sample code produces the following result.

CodeTools:-ProgramAnalysis:-StaticCallGraph

StaticCallGraph returns a directed graph which represents a static call graph for the input P. The vertices of the graph are strings which represent procedures or appliable modules, and a directed arc exists from f to g when there is an explicit reference to g in the body of f.

The output is a Maple graph suitable for use with commands from the GraphTheory package.

 > $\mathrm{with}\left(\mathrm{CodeTools}\left[\mathrm{ProgramAnalysis}\right]\right):$
 > $G≔\mathrm{StaticCallGraph}\left(\mathrm{maximize},\mathrm{maxdepth}=2\right)$
 ${G}{≔}{\mathrm{Graph 1: a directed unweighted graph with 22 vertices and 24 arc\left(s\right)}}$ (2.1)
 > $\mathrm{GraphTheory}:-\mathrm{Vertices}\left(G\right)$
 $\left[{"NumericEventHandler"}{,}{"convert"}{,}{"evalf"}{,}{"has"}{,}{"hastype"}{,}{"indets"}{,}{"length"}{,}{"max"}{,}{"maximize"}{,}{"min"}{,}{"minimize"}{,}{"minimize/Handler"}{,}{"minimize/cell/check"}{,}{"nops"}{,}{"op"}{,}{"select"}{,}{"selectremove"}{,}{"seq"}{,}{"simplify"}{,}{"sort"}{,}{"subs"}{,}{"type"}\right]$ (2.2)
 > $\mathrm{GraphTheory}:-\mathrm{DrawGraph}\left(G,\mathrm{style}=\mathrm{spring}\right)$



ListTools:-Slice

The Slice command in the ListTools package slices a list into a sequence of sub-lists. The number of sub-lists is user-provided, and the lengths of the sub-lists in the sequence differ by at most one. Note that if the specified number of sub-lists is greater than the number of elements in the original list, then the result is a sequence of sub-lists consisting of a single element, followed by empty lists. For example:

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[\mathrm{seq}\left("a".."j"\right)\right]$
 ${L}{≔}\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"f"}{,}{"g"}{,}{"h"}{,}{"i"}{,}{"j"}\right]$ (3.1)
 > $\mathrm{Slice}\left(L,3\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}\right]{,}\left[{"e"}{,}{"f"}{,}{"g"}\right]{,}\left[{"h"}{,}{"i"}{,}{"j"}\right]$ (3.2)

For comparison, the LengthSplit command, which splits the list based on a target length, often returns sub-lists with lengths of larger difference:

 > $\mathrm{LengthSplit}\left(L,3\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}\right]{,}\left[{"d"}{,}{"e"}{,}{"f"}\right]{,}\left[{"g"}{,}{"h"}{,}{"i"}\right]{,}\left[{"j"}\right]$ (3.3)
 > $\mathrm{LengthSplit}\left(L,4\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}\right]{,}\left[{"e"}{,}{"f"}{,}{"g"}{,}{"h"}\right]{,}\left[{"i"}{,}{"j"}\right]$ (3.4)

Miscellaneous

 • The Worksheet package contains two new commands: RemoveSection for removing all sections from a Maple document, and TableOfContents for adding section headings to the beginning of a Maple document.