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

File: [local] / OpenXM / src / asir-doc / parts / builtin / list.texi (download)

Revision 1.4, Thu Dec 18 10:26:20 2003 UTC (20 years, 5 months ago) by ohara
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.3: +10 -8 lines

Add sections into the Risa/Asir manusl.
(vector, list, structure, asir grammer, and several functions.)

@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/list.texi,v 1.4 2003/12/18 10:26:20 ohara Exp $
\BJP
@node $B%j%9%H$N1i;;(B,,, $BAH$_9~$_H!?t(B
@section $B%j%9%H$N1i;;(B
\E
\BEG
@node Lists,,, Built-in Function
@section Lists
\E

@menu
* car cdr cons append reverse length::
@end menu

\JP @node car cdr cons append reverse length,,, $B%j%9%H$N1i;;(B
\EG @node car cdr cons append reverse length,,, Lists
@subsection @code{car}, @code{cdr}, @code{cons}, @code{append}, @code{reverse}, @code{length}
@findex car
@findex cdr
@findex cons
@findex append
@findex reverse
@findex length

@table @t
@item car(@var{list})
\JP :: $B6u$G$J$$(B @var{list} $B$N@hF,MWAG(B. 
\EG :: The first element of the given non-null list @var{list}.
@item cdr(@var{list})
\JP :: $B6u$G$J$$(B @var{list} $B$+$i@hF,MWAG$r<h$j=|$$$?%j%9%H(B. 
\EG :: A list obtained by removing the first element of the given non-null list @var{list}.
@item cons(@var{obj},@var{list})
\JP :: @var{list} $B$N@hF,$K(B @var{obj} $B$rIU$12C$($?%j%9%H(B. 
\EG :: A list obtained by adding an element @var{obj} to the top of the given list @var{list}.
@item @t{append}(@var{list1},@var{list2})
\JP :: @var{list1} $B$H(B @var{list2} $B$r$3$N=g$K(B 1 $B$D$K$7$?%j%9%H(B. 
\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}.
@item @t{reverse}(@var{list})
\JP :: @var{list} $B$r5U=g$K$7$?%j%9%H(B. 
\EG :: reversed list of @var{list}.
@item length(@var{list}|@var{vect})
\JP :: @var{list} $B$ND9$5(B, $B$^$?$O(B @var{vect} $B$ND9$5(B. 
\EG :: Number of elements in a list @var{list} and a vector @var{vect}.
@end table

@table @var
@item return
\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
\EG @code{car()} : arbitrary, @code{cdr()}, @code{cons()}, @code{append()}, @code{reverse()} : list,  @code{length()} : non-negative integer
@item list list1 list2
\JP $B%j%9%H(B
\EG list
@item obj
\JP $BG$0U(B
\EG arbitrary
@end table

@itemize @bullet
\BJP
@item
$B%j%9%H$O(B @t{[}@var{obj1},@var{obj2},...@t{]} $B$HI=$5$l$k(B. @var{obj1} $B$,(B
$B@hF,MWAG$G$"$k(B. 
@item
@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. 
@item 
@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. 
@item 
@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. 
@item
@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. 
@item
@code{reverse()} $B$O(B, @var{list} $B$r5U=g$K$7$?%j%9%H$r=PNO$9$k(B. 
@item
@code{length()} $B$O(B, @var{list} $B$^$?$O(B @var{vect} $B$ND9$5$r=PNO$9$k(B. $B9TNs$NMWAG$N8D?t$O(B, @code{size()} $B$rMQ$$$k(B. 
@item
$B%j%9%H$OFI$_=P$7@lMQ$G(B, $BMWAG$NF~$lBX$($O$G$-$J$$(B. 
@item
$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
$B$7$?8e(B @code{car()} $B$rE,MQ$9$k$3$H$K$h$j2DG=$G$"$k$,(B, $BJXK!$H$7$F(B, 
$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
$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, 
$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. 
@item
@code{cdr()} $B$O?7$7$$%;%k$r@8@.$7$J$$$,(B, @code{append()} $B$O(B, $B<B:]$K$O(B
$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, 
$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. 
@code{reverse()} $B$K4X$7$F$bF1MM$G$"$k(B. 
\E
\BEG
@item
A list is written in @b{Asir} as @t{[}@var{obj1},@var{obj2},@dots{}@t{]}.
Here, @var{obj1} is the first element.
@item
Function @code{car()} outputs the first element of a non-null list.
For a null list, the result should be undefined. In the current
implementation, however, it outputs a null list.  This treatment for a
null list may subject to change in future, and users are suggested not
to use the tentative treatment for a null list for serious programming.
@item
Function @code{cdr()} outputs a list obtained by removing the first
element from the input non-null list.
For a null list, the result should be undefined. In the current
implementation, however, it outputs a null list.  This treatment for a
null list may subject to change in future, and users are suggested not
to use the tentative treatment for a null list for serious programming.
@item
Function @code{cons()} composes a new list from the input list @var{list}
and an arbitrary object @var{obj} by adding @var{obj} to the top of
@var{list}.
@item
Function @code{append()} composes a new list, which has all elements of
@var{list1} in the same ordering followed by all elements of @var{list2}
in the same ordering.
@item
Function @code{reverse()} returns a reversed list of @var{list}.
@item
Function @code{length()} returns a non-negative integer which is the
number of elements in the input list @var{list} and the input vector @var{vect}.
Note that function @code{size} should be used for counting elements
of @var{matrix}.
@item
Lists are read-only objects in @b{Asir}.  There elements cannot be
modified.
@item
The @var{n}-th element in a list can be referred to by applying the
function @code{cdr()} @var{n} times repeatedly and @code{cdr()} at last.
A more convenient way to access to the @var{n}-th element is the use
of bracket notation, that is, to attach an index @code{[@var{n}]}
like vectors and matrices.  The system, however, follow the
@var{n} pointers to access the desired element. Subsequently, much
time is spent for an element located far from the top of the list.
@item
Function @code{cdr()} does not create a new cell (a memory quantity).
Function @code{append()}, as a matter of fact, repeats @code{cons()}
for as many as the length of @var{list1} the first argument.
Subsequently, @code{append()} consumes much memory space if its
first argument is long.
Similar argument applies to function @code{reverse()}.
\E
@end itemize

@example
[0] L = [[1,2,3],4,[5,6]];
[[1,2,3],4,[5,6]]
[1] car(L);
[1,2,3]
[2] cdr(L);
[4,[5,6]]
[3] cons(x*y,L);
[y*x,[1,2,3],4,[5,6]]
[4] append([a,b,c],[d]);
[a,b,c,d]
[5] reverse([a,b,c,d]);
[d,c,b,a]
[6] length(L);
3
[7] length(ltov(L));
3
[8] L[2][0];
5
@end example