Trolltech Home | QSA-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

QSA-interest Archive, August 2005
Re: operator overloading, MATH operations on arrays


Message 1 in thread


Gunnar Sletta wrote:
> 
> John Cummings wrote:
> > How do I load another file within a script file? That is, how do I do the
> > equivalent of the C/C++ preprocessor:
> >
> > Also, is it possible to overload operators in QSA? I would like to operators
> > that work on Arrays. For example,
> >
> >    var a = new Array(1,2,3,4);
> >    var b = new Array(5,6,7,8);
> >    // I want c to be (6,8,10,12)
> >    var c = a + b;
> >    // I want d to be (5,12,21,32)
> >    var d = a * b;
> >
> > Any ideas? I know I can do functions. However, I don't want to write those
> > functions over and over again (hence the first question about including other
> > files).
> 
> This is not supported although adding hooks for operator overloading is
> something that is being considered for a future release.
> 
> -
> Gunnar

Hi fellow QSAer, John and Gunnar,

we have a very strong similar request concerning operator overloading
and handling of arrays containing numbers. 
Basically our customers want to be able to perform math operations on 
complete arrays just the way John described it above (and performing many
more tasks on mathematical arrays such as linear algebra, ...)

From my understanding of the QSA architecture doing this would not
necesarily require a fully blown operator overload functionality.
It could maybe solved by expanding the existing operator and math code
so that it first checks wether an incoming argument is an array or not.
In the case of an array the function would need to iterate over the
array.
Of course there would be glitches like what should happen if the 
arrays passed as arguments do not match in shape, length and dimension.
Due to nature of arrays in QSA one would also have to make sure the
arrays only contain numbers (double and int) and also that they are
rectangular.

Maybe a better solution would be to create a new object type MathArray
and to expand the operators and math functions to properly deal with the
MathArray. A bit similar to NumPython or Python's NumArray extension.

What is TrollTechs position on this and is there anybody else out
there (besides John) who would need such functionality?


best regards

 Wolfgang


P.S.: On a side note: TT, what is the feature roadmap for QSA?
      How about adding a package mechanism and named arguments / Named 
      parameters for functions (such as described in JavaScript 2)?

____________
Virus checked: AVK 15.0.6672 from 17.08.2005