17.05.2015 Views

zl:1 - FTP

zl:1 - FTP

zl:1 - FTP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

nreverse 368<br />

I<br />

nreverse sequence Function<br />

nreverse returns a sequence containing the same elements as sequence, but<br />

in reverse order. The result mayor may not be eq to the argument, so it<br />

is usually wise to say something like (setq x (nreverse x», because<br />

(nreverse x) is not guaranteed to leave the reversed value in x.<br />

sequence can be either a list or a vector (one-dimensional array). Note that<br />

nil is considered to be a sequence, of length zero.<br />

For example:<br />

(setq item-list '(heron stork loon owl»<br />

=> (HERON STORK LOON OWL)<br />

(nreverse item-list) => (OWL LOON STORK HERON)<br />

item-list => (HERON)<br />

nreverse is the destructive version of reverse.<br />

For a table of related items: See the section "Functions for Modifying<br />

Lists" in Symbolics Common Lisp: Language Concepts.<br />

For a table of related items: See the section "Sequence Modification" in<br />

Symbolics Common Lisp: Language Concepts.<br />

<strong>zl</strong>:nreverse list Function<br />

<strong>zl</strong>:nreverse reverses its argument, which should be a list. The argument<br />

is destroyed by rplacds all through the list (see <strong>zl</strong>:reverse). Example:<br />

(<strong>zl</strong> :nreverse '(a b c» => (c b a)<br />

<strong>zl</strong>:nreverse could have been defined by:<br />

(de fun nreverse (x)<br />

(cond «null x) nil)<br />

«nreverse1 x nil»»<br />

(de fun nreverse1 (x y)<br />

; auxiliary function<br />

(cond «null (cdr x» (rplacd x y»<br />

«nreverse1 (cdr x) (rplacd x y»»)<br />

;; this last call depends on order of argument evaluation.<br />

<strong>zl</strong>:nreverse does something inefficient with cdr-coded lists, because it just<br />

uses rplacd in the straightforward way. See the section "Cdr-Coding" in<br />

Symbolics Common Lisp: Language Concepts. Using <strong>zl</strong>:reverse might be<br />

preferable in some cases.<br />

For a table of related items: See the section "Functions for Modifying<br />

Lists" in Symbolics Common Lisp: Language Concepts.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!