[BACK]Return to list.texi CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc / parts / builtin

Annotation of OpenXM/src/asir-doc/parts/builtin/list.texi, Revision 1.2

1.2     ! noro        1: @comment $OpenXM$
        !             2: \BJP
1.1       noro        3: @node $B%j%9%H$N1i;;(B,,, $BAH$_9~$_H!?t(B
                      4: @section $B%j%9%H$N1i;;(B
1.2     ! noro        5: \E
        !             6: \BEG
        !             7: @node Lists,,, Built-in Function
        !             8: @section Lists
        !             9: \E
1.1       noro       10:
                     11: @menu
                     12: * car cdr cons append reverse length::
                     13: @end menu
                     14:
1.2     ! noro       15: \JP @node car cdr cons append reverse length,,, $B%j%9%H$N1i;;(B
        !            16: \EG @node car cdr cons append reverse length,,, Lists
1.1       noro       17: @subsection @code{car}, @code{cdr}, @code{cons}, @code{append}, @code{reverse}, @code{length}
                     18: @findex car
                     19: @findex cdr
                     20: @findex cons
                     21: @findex append
                     22: @findex reverse
                     23: @findex length
                     24:
                     25: @table @t
                     26: @item car(@var{list})
1.2     ! noro       27: \JP :: $B6u$G$J$$(B @var{list} $B$N@hF,MWAG(B.
        !            28: \EG :: The first element of the given non-null list @var{list}.
1.1       noro       29: @item cdr(@var{list})
1.2     ! noro       30: \JP :: $B6u$G$J$$(B @var{list} $B$+$i@hF,MWAG$r<h$j=|$$$?%j%9%H(B.
        !            31: \EG :: A list obtained by removing the first element of the given non-null list @var{list}.
1.1       noro       32: @item cons(@var{obj},@var{list})
1.2     ! noro       33: \JP :: @var{list} $B$N@hF,$K(B @var{obj} $B$rIU$12C$($?%j%9%H(B.
        !            34: \EG :: A list obtained by adding an element @var{obj} to the top of the given list @var{list}.
1.1       noro       35: @item @t{append}(@var{list1},@var{list2})
1.2     ! noro       36: \JP :: @var{list1} $B$H(B @var{list2} $B$r$3$N=g$K(B 1 $B$D$K$7$?%j%9%H(B.
        !            37: \EG :: A list obtained by adding all elements in the list @var{list2} according to the order as it is to the last element in the list @var{list1}.
1.1       noro       38: @item @t{reverse}(@var{list})
1.2     ! noro       39: \JP :: @var{list} $B$r5U=g$K$7$?%j%9%H(B.
        !            40: \EG :: reversed list of @var{list}.
1.1       noro       41: @item length(@var{list})
1.2     ! noro       42: \JP :: @var{list} $B$ND9$5(B.
        !            43: \EG :: Number of elements in a list @var{list}.
1.1       noro       44: @end table
                     45:
                     46: @table @var
                     47: @item return
1.2     ! noro       48: \JP @code{car()} : $BG$0U(B, @code{cdr()}, @code{cons()}, @code{append()}, @code{reverse()} : $B%j%9%H(B,  @code{length()} : $B<+A3?t(B
        !            49: \EG @code{car()} : arbitrary, @code{cdr()}, @code{cons()}, @code{append()}, @code{reverse()} : list,  @code{length()} : non-negative integer
1.1       noro       50: @item list,list1,list2
1.2     ! noro       51: \JP $B%j%9%H(B
        !            52: \EG list
1.1       noro       53: @item obj
1.2     ! noro       54: \JP $BG$0U(B
        !            55: \EG arbitrary
1.1       noro       56: @end table
                     57:
                     58: @itemize @bullet
1.2     ! noro       59: \BJP
1.1       noro       60: @item
                     61: $B%j%9%H$O(B @t{[}@var{obj1},@var{obj2},...@t{]} $B$HI=$5$l$k(B. @var{obj1} $B$,(B
                     62: $B@hF,MWAG$G$"$k(B.
                     63: @item
                     64: @code{car()} $B$O(B, $B6u$G$J$$(B @var{list} $B$N@hF,MWAG$r=PNO$9$k(B. $B6u%j%9%H$,F~NO$5$l$?>l9g$O(B, $B6u%j%9%H$,=PNO$5$l$k(B.
                     65: @item
                     66: @code{cdr()} $B$O(B, $B6u$G$J$$(B @var{list} $B$+$i@hF,MWAG$r<h$j=|$$$?%j%9%H$r=PNO$9$k(B. $B6u%j%9%H$,F~NO$5$l$?>l9g$O(B, $B6u%j%9%H$,=PNO$5$l$k(B.
                     67: @item
                     68: @code{cons()} $B$O(B,  @var{list} $B$N@hF,$K(B @var{obj} $B$rIU$12C$($?%j%9%H$r=PNO$9$k(B.
                     69: @item
                     70: @code{append()} $B$O(B, @var{list1} $B$NMWAG$H(B @var{list2} $B$N$9$Y$F$NMWAG$r7k9g$5$;$?%j%9%H(B [@var{list1} $B$NMWAG$NJB$S(B,@var{list2} $B$NMWAG$NJB$S(B] $B$r=PNO$9$k(B.
                     71: @item
                     72: @code{reverse()} $B$O(B, @var{list} $B$r5U=g$K$7$?%j%9%H$r=PNO$9$k(B.
                     73: @item
                     74: @code{length()} $B$O(B, @var{list} $B$ND9$5$r=PNO$9$k(B. $B%Y%/%H%k5Z$S9TNs$NMWAG$N8D?t$O(B, @code{size()} $B$rMQ$$$k(B.
                     75: @item
                     76: $B%j%9%H$OFI$_=P$7@lMQ$G(B, $BMWAG$NF~$lBX$($O$G$-$J$$(B.
                     77: @item
                     78: $B%j%9%H$N(B @var{n} $BHVL\$NMWAG$N<h$j=P$7$O(B, @code{cdr()} $B$r(B @var{n} $B2sE,MQ(B
                     79: $B$7$?8e(B @code{car()} $B$rE,MQ$9$k$3$H$K$h$j2DG=$G$"$k$,(B, $BJXK!$H$7$F(B,
                     80: $B%Y%/%H%k(B, $B9TNs$J$I$NG[Ns$HF1MM(B, $B%$%s%G%C%/%9(B @code{[@var{n}]} $B$r8e$m$K(B
                     81: $BIU$1$k$3$H$K$h$j<h$j=P$9$3$H$,$G$-$k(B. $B$?$@$7(B, $B%7%9%F%`FbIt$G$O(B,
                     82: $B<B:]$K%]%$%s%?$r(B @var{n} $B2s$?$I$k$N$G(B, $B8e$m$NMWAG$[$I<h$j=P$7$K;~4V$,$+$+$k(B.
                     83: @item
                     84: @code{cdr()} $B$O?7$7$$%;%k$r@8@.$7$J$$$,(B, @code{append()} $B$O(B, $B<B:]$K$O(B
                     85: $BBh(B 1 $B0z?t$N%j%9%H$ND9$5$@$1$N(B @code{cons()} $B$N7+$jJV$7$H$J$k$?$a(B,
                     86: $BBh(B 1 $B0z?t$N%j%9%H$,D9$$>l9g$K$OB?$/$N%a%b%j$r>CHq$9$k$3$H$K$J$k(B.
                     87: @code{reverse()} $B$K4X$7$F$bF1MM$G$"$k(B.
1.2     ! noro       88: \E
        !            89: \BEG
        !            90: @item
        !            91: A list is written in @b{Asir} as @t{[}@var{obj1},@var{obj2},@dots{}@t{]}.
        !            92: Here, @var{obj1} is the first element.
        !            93: @item
        !            94: Function @code{car()} outputs the first element of a non-null list.
        !            95: For a null list, the result should be undefined. In the current
        !            96: implementation, however, it outputs a null list.  This treatment for a
        !            97: null list may subject to change in future, and users are suggested not
        !            98: to use the tentative treatment for a null list for serious programming.
        !            99: @item
        !           100: Function @code{cdr()} outputs a list obtained by removing the first
        !           101: element from the input non-null list.
        !           102: For a null list, the result should be undefined. In the current
        !           103: implementation, however, it outputs a null list.  This treatment for a
        !           104: null list may subject to change in future, and users are suggested not
        !           105: to use the tentative treatment for a null list for serious programming.
        !           106: @item
        !           107: Function @code{cons()} composes a new list from the input list @var{list}
        !           108: and an arbitrary object @var{obj} by adding @var{obj} to the top of
        !           109: @var{list}.
        !           110: @item
        !           111: Function @code{append()} composes a new list, which has all elements of
        !           112: @var{list1} in the same ordering followed by all elements of @var{list2}
        !           113: in the same ordering.
        !           114: @item
        !           115: Function @code{reverse()} returns a reversed list of @var{list}.
        !           116: @item
        !           117: Function @code{length()} returns a non-negative integer which is the
        !           118: number of elements in the input list @var{list}.
        !           119: Note that function @code{size} should be used for counting elements
        !           120: of @var{vector} and @var{matrix}.
        !           121: @item
        !           122: Lists are read-only objects in @b{Asir}.  There elements cannot be
        !           123: modified.
        !           124: @item
        !           125: The @var{n}-th element in a list can be referred to by applying the
        !           126: function @code{cdr()} @var{n} times repeatedly and @code{cdr()} at last.
        !           127: A more convenient way to access to the @var{n}-th element is the use
        !           128: of bracket notation, that is, to attach an index @code{[@var{n}]}
        !           129: like vectors and matrices.  The system, however, follow the
        !           130: @var{n} pointers to access the desired element. Subsequently, much
        !           131: time is spent for an element located far from the top of the list.
        !           132: @item
        !           133: Function @code{cdr()} does not create a new cell (a memory quantity).
        !           134: Function @code{append()}, as a matter of fact, repeats @code{cons()}
        !           135: for as many as the length of @var{list1} the first argument.
        !           136: Subsequently, @code{append()} consumes much memory space if its
        !           137: first argument is long.
        !           138: Similar argument applies to function @code{reverse()}.
        !           139: \E
1.1       noro      140: @end itemize
                    141:
                    142: @example
                    143: [0] L = [[1,2,3],4,[5,6]];
                    144: [[1,2,3],4,[5,6]]
                    145: [1] car(L);
                    146: [1,2,3]
                    147: [2] cdr(L);
                    148: [4,[5,6]]
                    149: [3] cons(x*y,L);
                    150: [y*x,[1,2,3],4,[5,6]]
                    151: [4] append([a,b,c],[d]);
                    152: [a,b,c,d]
                    153: [5] reverse([a,b,c,d]);
                    154: [d,c,b,a]
                    155: [6] length(L);
                    156: 3
                    157: [7] L[2][0];
                    158: 5
                    159: @end example
                    160:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>