1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2006-2008 - INRIA
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="list">
15 <refname>list</refname>
16 <refpurpose>a Scilab object and a list definition function</refpurpose>
19 <title>Calling Sequence</title>
20 <synopsis>list(a1, ..., an)</synopsis>
23 <title>Description</title>
25 Creates a <literal>list</literal> with elements
26 <varname>ai</varname>'s which are arbitrary Scilab objects
27 (<literal>matrix</literal>,
28 <literal>list</literal>,...). Type of
29 <literal>list</literal> objects is 15. <code>list()</code>
30 creates the empty <literal>list</literal> (0 element).
34 <title>Operations on lists</title>
37 <term>extraction</term>
40 <literal>[x,y,z,...]=L(v)</literal> where <literal>v</literal> is a vector of indices;
41 <literal>[x,y,z,...]=L(:)</literal> extracts all the elements.
46 <term>insertion at index i</term>
49 <code>L(i)=a</code> (note that it is not an
50 error to use <code>L(i)=a</code> with
51 <code><![CDATA[i > 1 + size(L)]]></code> but
52 some list entries are then undefined and their
53 extraction gives raise to an error).
58 <term>append an element in queue</term>
61 <code>L($+1)=e</code>.
66 <term>append an element in head</term>
72 operation <literal>e</literal> is an index 1,
73 the initial elements being shifted on the
83 <code>L(i)=null()</code> removes the <literal>i</literal>-th element of the list <literal>L</literal>.
88 <term>concatenation of two lists</term>
91 <code>L3 = lstcat(L1,L2)</code>.
96 <term>number of elements of a list</term>
99 you can use either <code>nb_elm = size(L)</code>
100 or <code>nb_elm = length(L)</code>.
105 <term>iterations with a list</term>
108 it is possible to use a list <literal>L</literal> with a <link linkend="for">for</link> loop:
109 <literal>for e=L,...,end</literal> is a loop with <literal>length(L)</literal>
110 iterations, the loop variable <literal>e</literal> being equal to <literal>L(i)</literal>
111 at the <literal>i</literal>-th iteration.
118 <title>Remarks</title>
120 Scilab provides also other kinds of list, the <link linkend="tlist">tlist</link> type (typed list) and
121 the <link linkend="mlist">mlist</link> type which are useful to define a new data type with operator
122 <link linkend="overloading">overloading</link> facilities (<link linkend="hypermatrices">hypermatrices</link> which are
123 multidimensional arrays in Scilab are in fact <emphasis>mlist</emphasis>).
126 Matlab <emphasis>struct</emphasis> are also available.
130 <title>Examples</title>
131 <programlisting role="example"><![CDATA[
132 l = list(1,["a" "b"]) // declaration of a basic list with a double & a vector of two strings
134 // l(0) - Does not exist!
135 l(1) // Access to the double value
136 l(2) // Access to the vector of strings
137 size(l(2)) // Size is 1,2
139 l(0) = "foo" // Insert at the beginning of the list
140 // l(0) - still does not exist
143 l($+1) = "hello" // Insert at the end
144 l(2) = "toto" // Override my double
145 l(3) = rand(1,2) // Override my vector of string
147 l(3) = null() // Remove the third element
149 lbis = list("gewurtz", "caipirina" ,"debug") // Declare a new list
150 lter = lstcat(l,lbis) // Merge the two list
151 size(lter) - size(lbis) - size(l) // must be zero
154 <refsection role="see also">
155 <title>See Also</title>
156 <simplelist type="inline">
158 <link linkend="null">null</link>
161 <link linkend="lstcat">lstcat</link>
164 <link linkend="tlist">tlist</link>
167 <link linkend="mlist">mlist</link>
170 <link linkend="insertion">insertion</link>
173 <link linkend="extraction">extraction</link>
176 <link linkend="size">size</link>
179 <link linkend="length">length</link>