126 lines
6.8 KiB
HTML
126 lines
6.8 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE>14.1. Simple Sequence Functions</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Simple Sequence Functions">
|
|
<meta name="keywords" value="clm">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<b>Common Lisp the Language, 2nd Edition</b>
|
|
<BR> <HR><A NAME=tex2html3301 HREF="node143.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3299 HREF="node141.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3293 HREF="node141.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3303 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3304 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3302 HREF="node143.html"> ConcatenatingMapping, and </A>
|
|
<B>Up:</B> <A NAME=tex2html3300 HREF="node141.html"> Sequences</A>
|
|
<B> Previous:</B> <A NAME=tex2html3294 HREF="node141.html"> Sequences</A>
|
|
<HR> <P>
|
|
<H1><A NAME=SECTION001810000000000000000>14.1. Simple Sequence Functions</A></H1>
|
|
<P>
|
|
Most of the following functions perform simple operations on a single
|
|
sequence; <tt>make-sequence</tt> constructs a new sequence.
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>elt <i>sequence</i> <i>index</i></tt><P>This returns the element of <i>sequence</i> specified by <i>index</i>,
|
|
which must be a non-negative integer less than the length of the <i>sequence</i>
|
|
as returned by <tt>length</tt>.
|
|
The first element of a sequence has index <tt>0</tt>.
|
|
<P>
|
|
(Note that <tt>elt</tt> observes the fill pointer in those vectors that have
|
|
fill pointers. The array-specific function <tt>aref</tt> may be used
|
|
to access vector elements that are beyond the vector's fill pointer.)
|
|
<P>
|
|
<tt>setf</tt> may be used with <tt>elt</tt> to destructively replace
|
|
a sequence element with a new value.
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>subseq <i>sequence</i> <i>start</i> &optional <i>end</i></tt><P>This returns the subsequence of <i>sequence</i> specified by <i>start</i> and
|
|
<i>end</i>.
|
|
<tt>subseq</tt> <i>always</i> allocates a new sequence for a result; it never
|
|
shares storage with an old sequence. The result subsequence is always of
|
|
the same type as the argument <i>sequence</i>.
|
|
<P>
|
|
<tt>setf</tt> may be used with <tt>subseq</tt> to destructively replace
|
|
a subsequence with a sequence of new values; see also <tt>replace</tt>.
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>copy-seq <i>sequence</i></tt><P>A copy is made of the argument <i>sequence</i>; the result is <tt>equalp</tt>
|
|
to the argument but not <tt>eq</tt> to it.
|
|
<P><pre>
|
|
(copy-seq <i>x</i>) == (subseq <i>x</i> 0)
|
|
</pre><P>
|
|
but the name <tt>copy-seq</tt> is more perspicuous when applicable.
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>length <i>sequence</i></tt><P>The number of elements in <i>sequence</i> is returned as a non-negative integer.
|
|
If the sequence is a vector with a fill pointer,
|
|
the ``active length'' as specified by the fill pointer is returned
|
|
(see section <A HREF="node162.html#FILLPOINTER">17.5</A>).
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>reverse <i>sequence</i></tt><P>The result is a new sequence of the same kind as <i>sequence</i>,
|
|
containing the same elements but in reverse order.
|
|
The argument is not modified.
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>nreverse <i>sequence</i></tt><P>The result is a sequence containing the same elements as <i>sequence</i>
|
|
but in reverse order. The argument may be destroyed and re-used to
|
|
produce the result. The result may or may not be <tt>eq</tt> to the
|
|
argument, so it is usually wise to say something like
|
|
<tt>(setq x (nreverse x))</tt>, because simply <tt>(nreverse x)</tt> is not
|
|
guaranteed to leave a reversed value in <tt>x</tt>.
|
|
<P>
|
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
|
X3J13 voted in March 1989 (REMF-DESTRUCTION-UNSPECIFIED) <A NAME=15438> </A>
|
|
to clarify the permissible side effects of certain operations.
|
|
When the <i>sequence</i> is a list,
|
|
<tt>nreverse</tt> is permitted to perform a <tt>setf</tt> on any part,
|
|
<i>car</i> or <i>cdr</i>, of the top-level list structure of that list.
|
|
When the <i>sequence</i> is an array,
|
|
<tt>nreverse</tt> is permitted to re-order the elements of the given array
|
|
in order to produce the resulting array.
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<P>
|
|
<BR><b>[Function]</b><BR>
|
|
<tt>make-sequence <i>type</i> <i>size</i> &key :initial-element</tt><P>This returns a sequence of type <i>type</i> and of length <i>size</i>, each of
|
|
whose elements
|
|
has been initialized to the <tt>:initial-element</tt> argument.
|
|
If specified, the <tt>:initial-element</tt> argument must be an object that
|
|
can be an element of a sequence of type <i>type</i>.
|
|
For example:
|
|
<P><pre>
|
|
(make-sequence '(vector double-float)
|
|
100
|
|
:initial-element 1d0)
|
|
</pre><P>
|
|
If an <tt>:initial-element</tt> argument is not specified, then the sequence will
|
|
be initialized in an implementation-dependent way.
|
|
<P>
|
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
|
X3J13 voted in January 1989
|
|
(ARGUMENTS-UNDERSPECIFIED) <A NAME=15458> </A>
|
|
to clarify that the <i>type</i> argument
|
|
must be a type specifier, and the <i>size</i> argument
|
|
must be a non-negative integer less than the value of
|
|
<tt>array-dimension-limit</tt>.
|
|
<P>
|
|
X3J13 voted in June 1989 (SEQUENCE-TYPE-LENGTH) <A NAME=15464> </A> to specify that
|
|
<tt>make-sequence</tt> should signal an error if the sequence <i>type</i> specifies the
|
|
number of elements and the <i>size</i> argument is different.
|
|
<P>
|
|
X3J13 voted in March 1989 (CHARACTER-PROPOSAL) <A NAME=15470> </A>
|
|
to specify that if <i>type</i> is <tt>string</tt>, the result is the same
|
|
as if <tt>make-string</tt> had been called with the same <i>size</i>
|
|
and <tt>:initial-element</tt> arguments.
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3301 HREF="node143.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3299 HREF="node141.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3293 HREF="node141.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3303 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3304 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3302 HREF="node143.html"> ConcatenatingMapping, and </A>
|
|
<B>Up:</B> <A NAME=tex2html3300 HREF="node141.html"> Sequences</A>
|
|
<B> Previous:</B> <A NAME=tex2html3294 HREF="node141.html"> Sequences</A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|