 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] operator overloading
| [MUG] operator overloading |
|
Author: Jarausch
Posted: Thu, 31 Oct 2002 11:15:11 +0100
|
>> From: "jarausch"
Hi,
as newbee in Maple and coming from C++ (and Scilab and Matlab) I have
some questions on simple "OO"-principles in Maple.
I have noticed that with LinearAlgebra (e.g.) the multiplication '*'
between 2 objects of class Matrix is correctly interpreted as matrix
multiplication. Is this a builtin special case or can one write a module
which does similar things (e.g. arithmetic in a finite field used with
the standard operators +,-,*,/)
Furthermore, is it possible to overload the assignment operator as well
( e.g. if x is an element of a self-grown module F7, then
x=11 should be interpreted as x= 11 mod 7 ?)
Thanks for any hints,
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
Aachen University
D 52056 Aachen, Germany
|
| [MUG] Re: operator overloading |
|
Author: Dr Francis J Wright
Posted: Fri, 1 Nov 2002 17:40:10 -0000
|
>> From: "Dr Francis J. Wright" "F.J.Wright"
From: "jarausch"
| as newbee in Maple and coming from C++ (and Scilab and Matlab) I have
| some questions on simple "OO"-principles in Maple.
|
| I have noticed that with LinearAlgebra (e.g.) the multiplication '*'
| between 2 objects of class Matrix is correctly interpreted as matrix
| multiplication. Is this a builtin special case or can one write a module
| which does similar things (e.g. arithmetic in a finite field used with
| the standard operators +,-,*,/)
It is more usual to use . for Matrix multiplication; * will not always work.
You can use a module to overload the standard operators, as I discuss in the
final chapter of my book "Computing with Maple" on Object Orientation and
Modules; see http://centaur.maths.qmul.ac.uk/CwM/ for details. I construct
a module to support block matrices as an example. You might like to
download the solutions to the exercises for Chapter 15, which are available
as a Maple 6 worksheet under "Exercise solutions". The block matrix package
is in the form of a plain text file, which is intended to be read into the
Maple worksheet.
| Furthermore, is it possible to overload the assignment operator as well
| ( e.g. if x is an element of a self-grown module F7, then
| x=11 should be interpreted as x= 11 mod 7 ?)
The Maple assignment operator is :=, but I am not aware that it can be
overloaded. This may be connected with the fact that assignments are
statements and not expressions in Maple, unlike in C, etc. (Maple is not an
object-oriented language, although the module facility that was introduced
in Maple 6 supports some object orientation.)
Francis
---
Dr Francis J. Wright
School of Mathematical Sciences, Queen Mary
University of London, Mile End Road, London E1 4NS, UK
Tel: 020 7882 5453 (direct); Fax: 020 8981 9587 (dept.)
"F.J.Wright" http://centaur.maths.qmul.ac.uk/
|
Previous by date: [MUG] Run out of memory, Robert Fischer
Next by date: [MUG] C switch/case by codegen, Nld
Previous thread: [MUG] Animation of drawing a function point-by-point, Sandy Yates
Next thread: [MUG] C switch/case by codegen, Nld
|
|
|