[Scilab-users] a{i, j} specific extraction syntax with {} should not be introduced

Cedric Delamarre cedric.delamarre at scilab-enterprises.com
Thu Feb 18 11:03:04 CET 2016


Hello Samuel,

Cells are specific container which can contain any types of Scilab, but
each element of a Cell matrix is a Cell. So, the rules for a Cell are
same than the rules for a matrix of something.

This feature is consistent with matrix extraction because when you
extract from or insert to a matrix of constant, the result is a matrix
of constant.

For example:
m = [1 2 3];
m(1:2) // extracts a matrix of constant
m(4) = 4 // inserts a constant
s = ["this" "is a" "string"];
s(1:2) // extracts a matrix of strings
s(4) = "true?" // inserts a string
a={1, %s, "test"};
a(1:2) // extracts a matrix of cells
a(4) = {5} // inserts a cell

This insert a cell at the forth position of "a" as you can insert a
constant in a matrix of constant and not a string.

For example:
m(5) = "5"
s(5) = 5
a(5) = 5

But, because Cells array can contain any Scilab types, we need a new
operator to insert another type in a cell.

a{4} = [5 5 5]
This insert the matrix of constant at the forth position of "a".
a{4} = {5 5 5}
This insert the Cell array at the forth position of "a".
a(4:6) = {5 5 5}
This insert each cell elements in "a".

If we apply that in your test cases, the first case returns an error
because a Cell array is a matrix of a homogeneous elements.
The second case is good because you insert a Cell in a Cell.
The third case returns an error because of the same reason as the first
one.

To conclude, keep in mind, Cells array are homogeneous array of cell
and not a list.

Hope this helps,

Le mercredi 17 février 2016 à 18:42 +0100, Samuel Gougeon a écrit :
> Le 17/02/2016 18:22, Samuel Gougeon a écrit :
> 
> > Hello,
> > 
> > Scilab 6.0 is being to introduce a very specific extraction syntax
> > for cells. 
> > Is it really worthwhile to do so, when everywhere else Scilab 6.0
> > tries to remove features that are too specific, and works to improve
> > consistency?
> 
> What about insertion?
> 
> --> C1 = { %pi %e ; %i %z};
> 
> --> C1(1) = 3
> 
> Wrong insertion: A Cell expected: use {...} instead of (...).
> 
> Why isn't this simple case silently handled, and the RHS scalar
> automatically wrapped in a cell to be accepted?
> 
> 
> --> C1([1 3]) = {3,"abc"}
>  C1  = 
> 
>   [1x1 constant]  [1x1 string    ]
>   [1x1 constant]  [1x1 polynomial]
> 
> 
> OK. So here, no need to use C1{..} to make the assignment
> distributive. Perfect!
> 
> --> C1([1 3]) = list(3,"abc")
> 
> Wrong insertion: A Cell expected: use {...} instead of (...).
> 
> This should be as well accepted, as soon as length(RHS list) == length
> of the LHS vector of indices.
> 
> 
> Could anyone find and show any case for which the {} specific
> insertion or extraction syntax would be worthwhile?
> 
> BR
> Samuel Gougeon
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-- 
Cédric DELAMARRE
Ingénieur de développement
-------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles
http://www.scilab-enterprises.com
-------------------------------------------




More information about the users mailing list