7.8 Other extensions
Syntax:assq
object a-list
assq
searches an association list for the first pair whose car iseq
to its object argument. It returns the first such pair that it finds; if no such entry is found, it returnsnil
.
assq
encounters an element in the list that is not a dotted pair, an error is signaled.
> (setq alist '(("one" . un) (deux . "two") (trois . "trois") ((quatre) . "four"))) (("one" . UN) (DEUX . "two") (TROIS . "trois") ((QUATRE) . "four")) > (assq "one" alist) NILdecache-eval Function> (assq 'deux alist) (DEUX . "two")
> (assq 'trois alist) (TROIS . "trois")
> (assq '(quatre) alist) NIL
> (assq nil alist) NIL
Syntax:decache-eval
decache-eval
forces the reexpansion of all function bodies when they are next executed.
decache-eval
need not be invoked in this situation.
> (defvar *expand-counter* 0) *EXPAND-COUNTER*define-function Function> (defmacro return-counter () (incf *expand-counter*)) RETURN-COUNTER
> (defun use-return-counter () (return-counter)) USE-RETURN-COUNTER
> *expand-counter* 1
> (use-return-counter) 2
> *expand-counter* 2
> (use-return-counter) 2
> (decache-eval) T
> *expand-counter* 2
> (use-return-counter) 3
> (use-return-counter) 3
Syntax:define-function
name function
define-function
is used by the Common Lisp macrodefun
to define a new function. It replaces the function cell of the named symbol with the specified function object.
> (defun dummy-function nil 101) DUMMY-FUNCTIONdefine-macro Function> (dummy-function) 101
> (define-function 'dummy-function #'+) DUMMY-FUNCTION
> (dummy-function) 0
> (dummy-function 1 2 3) 6
> (define-function 'dummy-function #'(lambda () 202)) DUMMY-FUNCTION
> (dummy-function) 202
Syntax:define-macro
name function
define-macro
is used by the Common Lisp macrodefmacro
to define a new macro. It replaces the function cell of the named symbol with the specified function object.
> (define-macro 'my-macro #'do) MY-MACRO > (my-macro ((i 0 (1+ i))) ((> i 2) i)) 3
*redefinition-action*
Syntax:delete-defstruct
name
delete-defstruct
takes a symbol that has been defined with the Common Lisp macrodefstruct
and removes that definition from the environment.
defstruct
form.
Syntax:delq
item list
delq
searches a list for the first top-level element that iseq
to the specified item. If it finds such an item,delq
deletes it and returns the modified list; otherwise, it returns the original list.
delq
is an abstraction of the Common Lisp functiondelete
and thus has similar return behavior. For any item x and list test-list, the following expressions are equivalent:
(delq x test-list) (delete x test-list :test #'eq)
delq
is destructively modified.
> (setq test-list '(a b c)) (A B C)> (delq 'a test-list) (B C)
> test-list ; DELQ did not modify this list. (A B C)
> (delq 'b test-list) (A C)
> test-list ; In this case, DELQ modified the list. (A C)
delete
(in CLtL2)
Syntax:deposit-byte
integer position size newbyte
deposit-byte
is similar to the Common Lisp functiondpb
except that it accepts position and size arguments instead of a bytespec argument. It replaces a field of bits within an integer.
load-byte
Syntax:destructuring-bind
pattern form-to-destructure {form}*
destructuring-bind
extracts components from, or destructures, a list. The value of the last form executed is returned as the result of executing the macro.
defmacro
.
destructuring-bind
is similar to the destructuring mechanism provided bydefmacro
; however,destructuring-bind
can be used in contexts other than macro expansion. The keyword&whole
is not permitted withdestructuring-bind
.
> (destructuring-bind (&key a b c) '(:b 2 :c 3 :a 1) (list a b c)) (1 2 3)displaced-array-p Function> (destructuring-bind ((a . b) c) (list (cons 'eh 'bee) 'sea) (list a b c)) (EH BEE SEA)
Syntax:displaced-array-p
array
displaced-array-p
tests whether the specified array is a displaced array. A displaced array is an array that shares elements with an existing array.
:displaced-to
keyword option to the Common Lisp functionmake-array
, two values are returned::displaced-index-offset
argument into that underlying arraymake-array
(in CLtL2)
Syntax:interrupts-deferred-p
interrupts-deferred-p
returns a non-nil
value if operating system interrupts are deferred; otherwise, it returnsnil
.
with-interrupts-deferred
, with-interrupts-allowed
Syntax:list-reverse
list
Syntax:list-nreverse
list
list-reverse
returns a true list consisting of the elements of the original list in reverse order. The last cdr is omitted because it isnil
for true lists.
list-nreverse
is likelist-reverse
but modifies its argument.
> (setq lst '(1 2 3)) (1 2 3)load-byte Function> (list-reverse lst) (3 2 1)
> lst (1 2 3)
> (list-nreverse lst) (3 2 1)
> lst (1)
> (list-reverse '(1 2 . 3)) (2 1)
Syntax:load-byte
integer position size
load-byte
is similar to the Common Lisp functionldb
except that it accepts position and size arguments instead of a bytespec argument. It extracts the bits of the specified field from the integer argument and returns the result as a nonnegative integer.
deposit-byte
Syntax:memq
object list
memq
searches a list for the first top-level element that iseq
to a given object. If it succeeds, it returns the tail of the list starting with that element. If no such element is found, it returnsnil
.
member
with a:test
argument ofeq
and with no:key
argument. However,memq
demonstrates better performance.
> (memq 1 '(a 1 "b")) (1 "b")parse-body Function> (memq 'a '(a 1 "b")) (A 1 "b")
> (memq "b" '(a 1 "b")) NIL
> (memq 2 '(1 2 . 3)) (2 . 3)
> (memq 3 '(1 2 . 3)) NIL
Syntax:parse-body
body&optional
environment doc-string-allowed-p
parse-body
separates the body part of a lambda expression into the following subparts and returns them in the order listed:nil
if there are nonenil
if there is none&body
argument to the Common Lisp macrodefmacro
, which is similar to a lambda expression without the explicitlambda
designator or a lambda list.
&body
argument todefmacro
.
nil
value for the optional doc-string-allowed-p argument specifies that the body argument is allowed to contain a documentation string; the default value ist
. A value ofnil
means there is no documentation string; any string in that position in the lambda expression in treated like any other atom.
Syntax:time1
form
time1
evaluates the specified form and returns the following information:nil
.
;;; TIME1 returns 11 values; none is the value of the computation. > (time1 (dotimes (i 1000) (append '(1 2 3) '(4 5 6)))) 1.087356 ; elapsed real time 1.007056 ; total CPU time NIL ; user CPU time NIL ; system CPU time 64 ; number of page faults available 0 ; number of disk I/O operations unavailable 0 ; number of network I/O operations unavailable 0 ; no bytes consed in dynamic space 0 ; no GC flips took place 43672 ; number of bytes consed in ephemeral space 0 ; no ephemeral garbage collectionswith-interrupts-deferred Macro
Syntax:with-interrupts-deferred
{form}*
Syntax:with-interrupts-allowed
{form}*
with-interrupts-deferred
defers any asynchronous interrupts that occur during the execution of the specified forms. All interrupts that are deferred are handled upon exit from this macro, unless there is an outer invocation of it. Process switching and interruption handling are also disabled; see Chapter 5, "The Multitasking Facility" for more information.with-interrupts-allowed
allows pending interrupts to be handled immediately; it locally suppresses the effect ofwith-interrupts-deferred
.with-interrupts-deferred
are deferred until the execution of the body is complete.
interrupt-process
, interrupts-deferred-p
,with-interruptions-allowed
,with-interruptions-inhibited
Syntax:xor
&rest
values
nil
; otherwise, it is false.
> (xor '3 nil) T> (xor nil t) T
> (xor (eql 3 4) (> 5 6)) NIL
Generated with Harlequin WebMaker