[Scilab-users] overloading size for tlist

philippe rouxph.22 at gmail.com
Sun Jul 23 11:43:26 CEST 2017


Hi to all,

I've created a new type "mytype", represented by tlist, and another type
"matrixmytype", for matrix of "mytype" object, represented by mlist .
I've created the function %matrixmytype_size to overload the function
"size" for "matrixmytype" objects (it works fine) . For compatibility
reason I would like that size(x), where typeof(x)=='mytype', retrieve
the value [1,1], but actually size(x) return the size of the tlist for x
 an "mytype" .

 Let's take a minimal example :

//*****************************************************
function x=mytype()
    x=tlist(['mytype' 'tab' 'pol' 'str'],..
            grand(2,3,'uin',1,3), ..          //x.tab
            poly(0,'x'), ..                   //x.pol
            'scilab')                         //x.str
endfunction

function [p,n]=%mytype_size(x)
    [p,n]=size(x.tab)
endfunction
//******************************************************

then in scilab console :


//***********************************
-->x=mytype()
 x  =


       x(1)

!mytype  tab  pol  str  !

       x(2)

    1.    3.    1.
    2.    1.    2.

       x(3)

    x

       x(4)

 scilab


-->[p,n]=%mytype_size(x)  // this is the expected result for size(x)
 n  =

    3.
 p  =

    2.

-->[p,n]=size(x)
              !--error 39
Nombre erroné d'arguments d'entrée.


-->size(x)
 ans  =

    4.

//****************************************************


My goal is only to ensure overloading compatibility between mytype and
matrixmytype  like for "double"  size(x) returns [1,1] if x is a scalar
and not a matrix.

Thank's for reading !

Philippe




More information about the users mailing list