[scilab-Users] can index starts from zero
Samuel GOUGEON
Samuel.Gougeon at univ-lemans.fr
Mon Oct 25 12:47:56 CEST 2010
Hello Calixte,
----- Message d'origine -----
De : Calixte Denizet
Date : 25/10/2010 12:27:
>
> Hello,
>
> There is a workaround: you can wrap your array in a mlist:
>
> a=[4 3 2 1];
> A=mlist(['Carray' 'array'],a);
> // overload extraction
> deff('y=%Carray_e(i,x)','y=x.array(i+1)');
> // overload insertion
> deff('z=%s_i_Carray(i,x,y)','y.array(i+1)=x;z=y;');
> // overload print
> deff('%Carray_p(x)','disp(x.array)');
>
> A(0) returns 4 and A(0)=5 inserts 5 at the first place. Have a look at
> the help page about overloading and mlist.
The price is that then you also have to redefine all usual operators such that
A*real, real*A, A+real, real+A, A+A, A*A, A>real, etc etc.
-->A*2
!--error 144
Undefined operation for the given operands.
check or define function %Carray_m_s for overloading.
-->A+1
!--error 144
Undefined operation for the given operands.
check or define function %Carray_a_s for overloading.
So yes, i agree that it is technically possible by defining a specific type
+ ALL needed functions -- not only insertion and extraction -- (and some
of them like find() that is often useful are not (yet?) overloadable)
However, it is a bit heavy, and decrease portability.
A quite big price just for a shift-by-one ;)
Regards
Samuel
More information about the users
mailing list