New Features in Maple 2018 - Language and Programming - Maplesoft

What's New in Maple 2018

Language and Programming




In addition to substantial improvements to the code editor, Maple 2018 also includes many other enhancements to its language and programming tools. 


Until Clause in For Loops

An optional until clause has been added to Maple’s loop control structure. When used, this clause is written in place of end do, and consists of the keyword until, followed by a Boolean expression. When the expression evaluates to true after the loop's body has executed, the loop terminates.

Since the until clause is checked at the end of the loop, a loop with an until clause and no other terminating condition (a to or while part) will execute its body at least once. 

For example, find the next prime after a given number using the isprime function. 

>  n := 37;
do n := n+1 until
   isprime(n);
n;
       
Typesetting:-mprintslash([n := 37], [37])
Typesetting:-mprintslash([n := 38], [38])
Typesetting:-mprintslash([n := 39], [39])
Typesetting:-mprintslash([n := 40], [40])
Typesetting:-mprintslash([n := 41], [41])
41
 

mint and maplemint

mint and maplemint generate static analysis information for procedures, giving parameter naming conflicts, unreachable code, unused parameters or variables, and more. The mint.exe tool is available for use with text files that contain Maple code, and maplemint() is a command that can be given Maple procedures to analyze. 

>  a:=proc() local b,i;
  b:=6;
  while (b>0) do
     for i from 1 to 6 do
        break;
        printf(`%d`,i);
     end do;
     for i in [1,3,5] do
        lprint(i);
        break;
        lprint(test);
     end do;
     b:=b-1;
  end do;
end proc:
>  maplemint(a);
 Procedure a()
  These names were used as global names but were not declared:  %d, test
  There is unreachable code following a break statement at statement 5:
     printf(%d,i)
  There is unreachable code following a break statement at statement 9:
     lprint(test)

In Maple 2018 the implementation of the external mint.exe tool was merged together with the maplemint() command so they could both analyze code in the same way.  As a result, the maplemint() command now works on modules and reports a wider class of warnings, and the external tool now supports the following new warnings: 

>  m := module()
   export p1 := proc( x )
      global G;
      x^2;
   end proc:
   export p2 := proc( y )
      local a, b;
      a := b*y;
      b := 42;
      a + b;
   end proc:
   export p3 := proc( z )
      with(LinearAlgebra);
      Determinant(z);
   end proc:
end module:
>  maplemint(m);
Nested Procedure p1( x ) on lines 1 to 2
 These global variables were declared, but never used:  G
Nested Procedure p2( y ) on lines 3 to 4
 These local variables were used before they were assigned a value:  b
Nested Procedure p3( z ) on lines 5 to 6
 Ineffectual call to with() inside a proc at statement 1: with(LinearAlgebra)

select, remove, and selectremove

The select, remove, and selectremove commands can now perform substitutions in-place in Arrays, Matrices, Vectors, tables, and objects. This functionality is specified by appending inplace as an index to the command name.  

When selectremove[inplace] is called, the first result is computed in-place, and the removed elements are returned in a new container that is returned as the second result. 

>  selectremove[inplace](type, [1,2,3,4,5,6,7,8,9], odd);
[1, 3, 5, 7, 9], [2, 4, 6, 8]
 

Inline Assignments

Assignments can now be used as, or embedded within, expressions. The assignment must be enclosed in parentheses. The result of the assignment is the evaluated right-hand side. 

>  g := x -> (x-1,x+1);
proc (x) options operator, arrow; `+`(x, `-`(1)), `+`(x, 1) end proc
 
>  g((z := 2));
1, 3
 
>  z
2
 

StringTools

DecodeEntities and EncodeEntities encode and decode strings with HTML entities. 

>  with(StringTools):
>  r := DecodeEntities("エ ン コ ー ド");
 
>  r := EncodeEntities( r ): lprint(r);
"エンコード"

Compare the Value and Structure of Expressions

SameStructure accepts two expressions, inert or otherwise, and compares their structure.  If they are the same in value and structure then this command returns true, otherwise false.

>  with(InertForm):
>  SameStructure(y = 1-x, y = 1-x)
true
 
>  SameStructure(1-x = y, y = 1-x)
false

Additional Updates

Object overloading of the select, remove, and selectremove functions, as well as andmap and ormap, is now supported.  

The RandomTools:-Generate command offers a new flavor called variable, and adds an exclude option to RandomTools:-Generate(integer(...))

The new RandomTools:-RandomExpand command produces a new expression in expanded form that is equivalent to the given expression. 



Ready for the next step?

Talk with our product specialists today for a free evaluation of Maple.

*Evaluations are not available for students or personal edition users.