• Aucun résultat trouvé

171 delete-if-not

Dans le document Symbolics Common Lisp: Language Dictionary (Page 174-178)

sequence may be destroyed and used to construct the result; however, the returned form mayor may not be eq to sequence.

For example:

(setq a-list '('5 a be» => ('5 A B C)

(delete-if-not #'atom a-list) => (A B C) a-list => ('5 A 8 C)

However,

(setq my-list '(0 1 => (0 1 0)

(delete-if-not #'zerop my-list) => (0 0) my-list => (0 1)

predicate is the test to be performed on each element.

sequence can be either a list or a vector (one-dimensional array). Note that nil is considered to be a sequence, of length zero.

The value of the keyword argument :l{ey, if non-nil, is a function that takes one argument. This function extracts from each element the part to be tested in place of the whole element.

For example:

(delete-if-not #'atom '((book 1) (math (room c» (text 3» :key #'second)

=> ((BOOK 1) (TEXT 3»

(deleteif-not #'zerop #(1 2 1) :key #' (lambda (x) (- x 1») => #(1 1) If the value of the :from-end argument is non-nil, it only affects the result when the :count argument is specified. In that case only the rightmost :count elements that satisfy the predicate are deleted.

For example:

(delete-if-not #'oddp '(4 2 4 1) :count 1) => (2 4 1)

(delete-if-not #'oddp '(4 2 4 1) :count 1 :from-end t) => (4 2 1) Use the keyword arguments :start and :end to delimit the portion of the sequence to be operated on.

:start and :end must be non-negative integer indices into the sequence.

:start must be less than or equal to :end, else an error is signalled. It defaults to zero (the start of the sequence).

:start indicates the start position for the operation within the sequence.

:end indicates the position of the first element in the sequence beyond the end of the operation. It defaults to nil (the length of the sequence).

If both :start and :end are omitted, the entire sequence is processed by default.

I

I

zl :del-if

For example:

(delete-if-not #'atom '('a 1 "list"» => (1 "list")

(delete-if-not #'numberp '(4 1 4) :start 1 :end 2) => (4 1 4) (delete-if-not #'evenp '(4 1 4) :start e :end 3) => (4 4)

The :count argument, if supplied, limits the number of elements deleted.

If more than :count elements of sequence satisfy the predicate, then only the leftmost :count of those elements are deleted.

For example:

(delete-if-not #'oddp '(1 1 2 2) :count 1 ) => (1 1 2) delete-if-not is the destructive version of remove-if-not.

For a table of related items: See the section "Sequence Modification" in Symbolics Common Lisp: Language Concepts.

172

zl:del-if predicate list Function

zl:del-if means "remove if this condition is true." predicate should be a function of one argument. A modified list is made by applying predicate to all the elements of list and removing the ones for which the predicate returns non-nil. zl:del-if is the destructive version of zl:rem-if, without the extra-lists &rest argument.

For a table of related items: See the section "Functions for Modifying Lists" in Symbolics Common Lisp: Language Concepts.

zl:del-if-not predicate list Function

zl:del-if-not means "remove if this condition is not true"; that is, it keeps the elements for which predicate is true.

predicate should be a function of one argument. A modified list is made by applying predicate to all of the elements of list and removing the ones for which the predicate returns nil. zl:del-if-not is the destructive version zl:rem-if-not, without the extra-lists &rest argument.

For a table of related items: See the section "Functions for Modifying Lists" in Symbolics Common Lisp: Language Concepts.

zl:delq item list &optional n Function

(zl:delq item list) returns the list with all occurrences of item removed. eq is used for the comparison. The argument list is actually modified

(rplacd'ed) when instances of item are spliced out. zl:delq should be used for value, not for effect. That is, use:

173

(setq a (delq 'b a»

rather than:

(delq 'b a)

denominator

These two are not equivalent when the first element of the value of a is b.

<zl:delq item list n) is like <zl:delq item list) except only the first n in-stances of item are deleted. n is allowed to be zero. If n is greater than or equal to the number of occurrences of item in the list, all occurrences of item in the list are deleted. Example:

(delq 'a '(b a c (a b) d a e» => (b c (a b) d e) zl:delq could have been defined by:

(defun delq (item list &optional (n -1»

(cond «or (atom list) (zerop n» list)

«eq item (car list»

(delq item (cdr list) (1- n»)

(t (rplacd list (delq item (cdr list) n»»)

If the third argument (n) is not supplied, it defaults to -1, which is effec-tively infinity, since it can be decremented any number of times without reaching zero.

zl:delq is a Symbolics extension to Common Lisp.

For a table of related items: See the section "Functions for Modifying Lists" in Symbolics Common Lisp: Language Concepts. .

denominator rational Function

If rational is a ratio, denominator returns the denominator of rational. If rational is an integer, denominator returns 1.

Examples:

(denominator 4/5) => 5 (denominator 3) => 1 (denominator 4/8) => 2

For a table of related items: See the section "Functions That Extract Com-ponents From a Rational Number" in Symbolics Common Lisp: Language Concepts.

deposit-byte into-value position size byte-value Function This is like dpb except that instead of using a byte specifier, the bit posi-tion and size are passed as separate arguments. The argument order is not analogous to that of dpb so that deposit-byte can be compatible with older versions of Lisp.

I

I

deposit-field

174

For a table of related items: See the section "Summary of Byte Manipula-tion FuncManipula-tions" in Symbolics Common Lisp: Language Concepts.

deposit-field newbyte bytespec integer Function

Returns an integer that is the same as integer except for the bits specified by bytespec which are taken from newbyte.

This is like function dpb ("deposit byte"), except that newbyte is not taken to be right-justified; the bytespec bits of newbyte are used for the bytespec bits of the result, with the rest of the bits taken from integer. integer must be an integer.

bytespec is built using function byte with bit size and position arguments.

deposit-field could have been defined as follows:

(deposi t-fi el d newbyte bytespec integer) ==>

(dpb (1 db bytespec newbyte) bytespec integer) Example:

(deposit-field #0239 (byte 6 3) #04567) => #04237

For a table of related items: See the section "Summary of Byte Manipula-tion FuncManipula-tions" in Symbolics Common Lisp: Language Concepts.

:describe Message

The object that receives this message should describe itself, printing a description onto the *standard-output* stream. The describe function sends this message when it encounters an instance.

The :describe method of flavor:vanilla calls flavor:describe-instance, which prints the following information onto the *standard-output* stream:

a description of the instance, the name of its flavor, and the names and values of its instance variables. It returns the instance. For example:

(send cell-object :describe)

-->#<CELL 1169762135>, an object of flavor CELL, has instance variable values:

X: 24

Y:

STATUS:

NEXT-STATUS:

NEIGHBORS:

#<CELL 1169762135>

3 :ALIVE unbound unbound

Dans le document Symbolics Common Lisp: Language Dictionary (Page 174-178)