version 1.1, 1999/12/08 05:47:44 |
version 1.4, 2003/12/18 10:26:20 |
|
|
|
@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/list.texi,v 1.3 2003/04/19 15:44:58 noro Exp $ |
|
\BJP |
@node $B%j%9%H$N1i;;(B,,, $BAH$_9~$_H!?t(B |
@node $B%j%9%H$N1i;;(B,,, $BAH$_9~$_H!?t(B |
@section $B%j%9%H$N1i;;(B |
@section $B%j%9%H$N1i;;(B |
|
\E |
|
\BEG |
|
@node Lists,,, Built-in Function |
|
@section Lists |
|
\E |
|
|
@menu |
@menu |
* car cdr cons append reverse length:: |
* car cdr cons append reverse length:: |
@end menu |
@end menu |
|
|
@node car cdr cons append reverse length,,, $B%j%9%H$N1i;;(B |
\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} |
@subsection @code{car}, @code{cdr}, @code{cons}, @code{append}, @code{reverse}, @code{length} |
@findex car |
@findex car |
@findex cdr |
@findex cdr |
|
|
|
|
@table @t |
@table @t |
@item car(@var{list}) |
@item car(@var{list}) |
:: $B6u$G$J$$(B @var{list} $B$N@hF,MWAG(B. |
\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}) |
@item cdr(@var{list}) |
:: $B6u$G$J$$(B @var{list} $B$+$i@hF,MWAG$r<h$j=|$$$?%j%9%H(B. |
\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}) |
@item cons(@var{obj},@var{list}) |
:: @var{list} $B$N@hF,$K(B @var{obj} $B$rIU$12C$($?%j%9%H(B. |
\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}) |
@item @t{append}(@var{list1},@var{list2}) |
:: @var{list1} $B$H(B @var{list2} $B$r$3$N=g$K(B 1 $B$D$K$7$?%j%9%H(B. |
\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}) |
@item @t{reverse}(@var{list}) |
:: @var{list} $B$r5U=g$K$7$?%j%9%H(B. |
\JP :: @var{list} $B$r5U=g$K$7$?%j%9%H(B. |
@item length(@var{list}) |
\EG :: reversed list of @var{list}. |
:: @var{list} $B$ND9$5(B. |
@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 |
@end table |
|
|
@table @var |
@table @var |
@item return |
@item return |
@code{car()} : $BG$0U(B, @code{cdr()}, @code{cons()}, @code{append()}, @code{reverse()} : $B%j%9%H(B, @code{length()} : $B<+A3?t(B |
\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 |
@item list,list1,list2 |
\EG @code{car()} : arbitrary, @code{cdr()}, @code{cons()}, @code{append()}, @code{reverse()} : list, @code{length()} : non-negative integer |
$B%j%9%H(B |
@item list list1 list2 |
|
\JP $B%j%9%H(B |
|
\EG list |
@item obj |
@item obj |
$BG$0U(B |
\JP $BG$0U(B |
|
\EG arbitrary |
@end table |
@end table |
|
|
@itemize @bullet |
@itemize @bullet |
|
\BJP |
@item |
@item |
$B%j%9%H$O(B @t{[}@var{obj1},@var{obj2},...@t{]} $B$HI=$5$l$k(B. @var{obj1} $B$,(B |
$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. |
$B@hF,MWAG$G$"$k(B. |
|
|
@item |
@item |
@code{reverse()} $B$O(B, @var{list} $B$r5U=g$K$7$?%j%9%H$r=PNO$9$k(B. |
@code{reverse()} $B$O(B, @var{list} $B$r5U=g$K$7$?%j%9%H$r=PNO$9$k(B. |
@item |
@item |
@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. |
@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 |
@item |
$B%j%9%H$OFI$_=P$7@lMQ$G(B, $BMWAG$NF~$lBX$($O$G$-$J$$(B. |
$B%j%9%H$OFI$_=P$7@lMQ$G(B, $BMWAG$NF~$lBX$($O$G$-$J$$(B. |
@item |
@item |
|
|
$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$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. |
$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. |
@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 |
@end itemize |
|
|
@example |
@example |
|
|
[d,c,b,a] |
[d,c,b,a] |
[6] length(L); |
[6] length(L); |
3 |
3 |
[7] L[2][0]; |
[7] length(ltov(L)); |
|
3 |
|
[8] L[2][0]; |
5 |
5 |
@end example |
@end example |
|
|