Language and Programming - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 2015 : updates/Maple2015/Language

Language and Programming

 

Data Structures

Object Inheritance

More Updates

Data Structures

• 

Allow double as an alias for float[8]

M  Matrix2,2,datatype = double

0.0.0.0.

(1.1)
• 

max/min optionally return position

  maxindex1,2,4,3

3

(1.2)

minindex2,1,3,4

2

(1.3)

maxindex,defined1,2,undefined,5,3

4

(1.4)

Object Inheritance

Objects can now inherit from other object declarations following the usual rules for single inheritance in object-oriented programming.
To inherit from an existing declared object, simply include the name of the parent object in parentheses after the object option in the declaration of the descendant object.


Example: Consider a simple definition of a Vehicle object:

You can derive a subclass of Vehicle called Car which inherits properties from Vehicle simply by including the parent object name in the object option when defining the module:

You can see that a Car is a Vehicle:

myCar  ObjectCar:typemyCar, Vehicle

true

(2.1)

SetSpeedmyCar, 88mph

88mph

(2.2)

GetSpeedmyCar

88mph

(2.3)

You can also define other objects, such as Bicycle, which inherit from Vehicle:

Notice that while a Bicycle object is a Vehicle, it is not a Car, just as you would expect:


myBike  ObjectBicycle:type Bicycle, Vehicle 

true

(2.4)

type Bicycle, Car

false

(2.5)

Furthermore, if you attempt to access an export such as HasAutomaticTransmission on a Bicycle object, this results in an error, since this export is only provided for a Car object:

  myBike:-HasAutomaticTransmission

Error, module does not export `HasAutomaticTransmission`

HasAutomaticTransmissionmyCar

false

(2.6)

For more details on object inheritance, read about object creation.

More Updates

cat

• 

Enable concatenation of a string with a constant:

catx=, 2.5

x=2.5

(3.1.1)

rand

• 

Allow rand to accept floating-point intervals as input:

  RealRand  rand0.0 .. 1.0;

→RandomTools:-Generatefloat'range'=0...1.0,'method'='uniform'

(3.2.1)

  for i to 5 do RealRand end do;

0.8953600369

(3.2.2)

tablemerge

The new command tablemerge allows two tables to be merged together.

T1  tablea=100,b=200:

T2 tablea=150, c=300:

tablemerge T1, T2 

tablea=150,c=300,b=200

(3.3.1)

In the resulting table, the value associated to key a in T1 was overridden by the value associated to the same key in T2.

If you would prefer they be added, you can specify this by providing a custom merge function:

  tablemerge T1, T2, `+` 

tablea=250,c=300,b=200

(3.3.2)