Google

Go to the first, previous, next, last section, table of contents.


newvect

newvect(len[,list])
:: Creates a new vector object with its length len.
return
vector
len
non-negative integer
list
list
  • Creates a new vector object with its length len and its elements all cleared to value 0. If the second argument, a list, is given, the vector is initialized by the list elements. Elements are used from the first through the last. If the list is short for initializing the full vector, 0's are filled in the remaining vector elements.
  • Elements are indexed from 0 through len-1. Note that the first element has not index 1.
  • List and vector are different types in Asir. Lists are conveniently used for representing many data objects whose size varies dynamically as computation proceeds. By its flexible expressive power, it is also conveniently used to describe initial values for other structured objects as you see for vectors. Access for an element of a list is performed by following pointers to next elements. By this, access costs for list elements differ for each element. In contrast to lists, vector elements can be accessed in a same time, because they are accessed by computing displacements from the top memory location of the vector object. Note also, in Asir, modification of an element of a vector causes modification of the whole vector itself, while modification of a list element does not cause the modification of the whole list object. By this, in Asir language, a vector element designator can be a left value of assignment statement, but a list element designator can NOT be a left value of assignment statement.
  • No distinction of column vectors and row vectors in Asir. If a matrix is applied to a vector from left, the vector shall be taken as a column vector, and if from right it shall be taken as a row vector.
  • The length (or size or dimension) of a vector is given by function size().
  • When a vector is passed to a function as its argument (actual parameter), the vector element can be modified in that function.
  • A vector is displayed in a similar format as for a list. Note, however, there is a distinction: Elements of a vector are separated simply by a `blank space', while those of a list by a `comma.'
[0] A=newvect(5);
[ 0 0 0 0 0 ]
[1] A=newvect(5,[1,2,3,4,[5,6]]);
[ 1 2 3 4 [5,6] ]
[2] A[0];
1
[3] A[4];
[5,6]
[4] size(A);
[5]
[5] def afo(V) { V[0] = x; }
[6] afo(A)$
[7] A;
[ x 2 3 4 [5,6] ]
References
section newmat, section size, section vtol.


Go to the first, previous, next, last section, table of contents.