[Scilab-users] overloading size for tlist

Samuel Gougeon sgougeon at free.fr
Sun Jul 23 14:09:49 CEST 2017


Hello Philippe,

In Scilab 5, size() is overloadable only for mlist(), not for tlist().
In Scilab 6, it is overloadable for foth.
So, to be compatible with both Scilab 5 and 6, you shall define your 
object as a mlist instead of tlist.

Best regards
Samuel

Le 23/07/2017 à 11:43, philippe a écrit :
> 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
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users





More information about the users mailing list