next up previous contents index
Next: 3. Programming Up: 2.12 Indexing Previous: 2.12.1 Indexing in matrices

2.12.2 Indexing in lists

The following session illustrates how to create lists and insert/extract entries in lists and tlists.
 
-->a=33;b=11;c=0;
 
-->l=list();l(0)=a
 l  =
 
 
       l(1)
 
    33.  
 
-->l=list();l(1)=a
 l  =
 
 
       l(1)
 
    33.  
 
-->l=list(a);l(2)=b
 l  =
 
 
       l(1)
 
    33.  
 
       l(2)
 
    11.  
 
-->l=list(a);l(0)=b
 l  =
 
 
       l(1)
 
    11.  
 
       l(2)
 
    33.  
 
-->l=list(a);l(1)=c
 l  =
 
 
       l(1)
 
    0.  
 
-->l=list();l(0)=null()
 l  =
 
     ()
 
-->l=list();l(1)=null()
 l  =
 
     ()
 
-->//
 
-->i='i';
 
-->l=list(a,list(c,b),i);l(1)=null()
 l  =
 
 
       l(1)
 
 
        l(1)(1)
 
    0.  
 
        l(1)(2)
 
    11.  
 
       l(2)
 
 i   
 
-->l=list(a,list(c,list(a,c,b),b),'h');
 
-->l(2)(2)(3)=null()
 l  =
 
 
       l(1)
 
    33.  
 
       l(2)
 
 
        l(2)(1)
 
    0.  
 
        l(2)(2)
 
 
         l(2)(2)(1)
 
    33.  
 
         l(2)(2)(2)
 
    0.  
 
        l(2)(3)
 
    11.  
 
       l(3)
 
 h   
 
-->//
 
-->dts=list(1,tlist(['x';'a';'b'],10,[2 3]));
 
-->dts(2)('a')
 ans  =
 
    10.  
 
-->dts(2)('b')(1,2)
 ans  =
 
    3.  
 
-->[a,b]=dts(2)(['a','b'])
 b  =
 
!   2.    3. !
 a  =
 
    10.  
 
-->//
 
-->l=list(1,'qwerw',%s)
 l  =
 
 
       l(1)
 
    1.  
 
       l(2)
 
 qwerw   
 
       l(3)
 
    s   
 
-->l(1)='Changed'
 l  =
 
 
       l(1)
 
 Changed   
 
       l(2)
 
 qwerw   
 
       l(3)
 
    s   
 
-->l(0)='Added'
 l  =
 
 
       l(1)
 
 Added   
 
       l(2)
 
 Changed   
 
       l(3)
 
 qwerw   
 
       l(4)
 
    s   
 
-->l(6)=['one more';'added']
 l  =
 
 
       l(1)
 
 Added   
 
       l(2)
 
 Changed   
 
       l(3)
 
 qwerw   
 
       l(4)
 
    s   
 
       l(5)
 
    Undefined
 
       l(6)
 
!one more  !
!          !
!added     !
 
-->//
 
-->dts=list(1,tlist(['x';'a';'b'],10,[2 3]));
 
-->dts(2)('a')=33
 dts  =
 
 
       dts(1)
 
    1.  
 
       dts(2)
 
 
        dts(2)(1)
 
!x  !
!   !
!a  !
!   !
!b  !
 
        dts(2)(2)
 
    33.  
 
        dts(2)(3)
 
!   2.    3. !
 
-->dts(2)('b')(1,2)=-100
 dts  =
 
 
       dts(1)
 
    1.  
 
       dts(2)
 
 
        dts(2)(1)
 
!x  !
!   !
!a  !
!   !
!b  !
 
        dts(2)(2)
 
    33.  
 
        dts(2)(3)
 
!   2.  - 100. !
 
-->//
 
-->l=list(1,'qwerw',%s)
 l  =
 
 
       l(1)
 
    1.  
 
       l(2)
 
 qwerw   
 
       l(3)
 
    s   
 
-->l(1)
 ans  =
 
    1.  
 
-->[a,b]=l([3 2])
 b  =
 
 qwerw   
 a  =
 
    s   
 
-->l($)
 ans  =
 
    s   
 
-->//
 
-->L=list(33,list(l,33))
 L  =
 
 
       L(1)
 
    33.  
 
       L(2)
 
 
        L(2)(1)
 
 
         L(2)(1)(1)
 
    1.  
 
         L(2)(1)(2)
 
 qwerw   
 
         L(2)(1)(3)
 
    s   
 
        L(2)(2)
 
    33.


next up previous contents index
Next: 3. Programming Up: 2.12 Indexing Previous: 2.12.1 Indexing in matrices
Scilab Group