7.8 Other extensions

7.8.1 Reference pages

assq Function

Syntax:assq object a-list

The functionassq 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.

If the functionassq 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)
NIL

> (assq 'deux alist) (DEUX . "two")

> (assq 'trois alist) (TROIS . "trois")

> (assq '(quatre) alist) NIL

> (assq nil alist) NIL

decache-eval Function

Syntax:decache-eval

The functiondecache-eval forces the reexpansion of all function bodies when they are next executed.

You should normally use this only in exceptional situations or when debugging macros.

The first time that an interpreted function is called, it is replaced by a function object; all of the macros in the function body of this function object have been expanded. After a macro has been redefined or a function has been redefined as a macro, the reexpansion of the function body occurs automatically when the body of the function is next entered. The functiondecache-eval need not be invoked in this situation.

Redefining a function while that function is running can cause unpredictable results.

> (defvar *expand-counter* 0)
*EXPAND-COUNTER*

> (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

define-function Function

Syntax:define-function name function

The functiondefine-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.

If the function is currently traced, it remains traced but with the new definition.

The name argument is a symbol.

> (defun dummy-function nil 101)
DUMMY-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

define-macro Function

Syntax:define-macro name function

The functiondefine-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.

The name argument is a symbol.

If the function is currently traced, it remains traced but with the new definition.

> (define-macro 'my-macro #'do)
MY-MACRO
> (my-macro ((i 0 (1+ i))) ((> i 2) i))
3

See Also:*redefinition-action*

delete-defstruct Function

Syntax:delete-defstruct name

The functiondelete-defstruct takes a symbol that has been defined with the Common Lisp macrodefstruct and removes that definition from the environment.

This function also removes type information and function definitions created by thedefstruct form.

delq Function

Syntax:delq item list

The functiondelq 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.

The functiondelq 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)
In some instances, the list returned bydelq 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)

See Also:delete (in CLtL2)

deposit-byte Function

Syntax:deposit-byte integer position size newbyte

The functiondeposit-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.

The position argument is an integer that specifies the starting position of the bits to be replaced.

The size argument is an integer that specifies the length of the bit field being replaced.

There is no limit on the magnitude of the position and size arguments.

See Also: load-byte

destructuring-bind Macro

Syntax:destructuring-bind pattern form-to-destructure {form}*

The macrodestructuring-bind extracts components from, or destructures, a list. The value of the last form executed is returned as the result of executing the macro.

The pattern argument is equivalent to a lambda list of a form suitable to the Common Lisp macrodefmacro.

The symbols specified in the pattern argument name variables that are bound in the body of the macro to corresponding pieces of form-to-destructure. The body of the macro expansion function is specified by the form arguments. They are executed in order.

The destructuring mechanism provided bydestructuring-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)

> (destructuring-bind ((a . b) c) (list (cons 'eh 'bee) 'sea) (list a b c)) (EH BEE SEA)

displaced-array-p Function

Syntax:displaced-array-p array

The functiondisplaced-array-p tests whether the specified array is a displaced array. A displaced array is an array that shares elements with an existing array.

The array argument must be an array. If it was created by using the:displaced-to keyword option to the Common Lisp functionmake-array, two values are returned:

See Also:make-array (in CLtL2)

interrupts-deferred-p Function

Syntax:interrupts-deferred-p

The functioninterrupts-deferred-p returns a non-nil value if operating system interrupts are deferred; otherwise, it returnsnil.

See Also: with-interrupts-deferred, with-interrupts-allowed

list-reverse Function

list-nreverse Function

Syntax:list-reverse list

Syntax:list-nreverse list

The functionlist-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.

The functionlist-nreverse is likelist-reverse but modifies its argument.

> (setq lst '(1 2 3))
(1 2 3)

> (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)

load-byte Function

Syntax:load-byte integer position size

The functionload-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.

The position argument is an integer that specifies the starting position of the bits to be extracted.

The size argument is an integer that specifies the length of the bit field being extracted.

There is no limit on the magnitude of the position and size arguments.

See Also: deposit-byte

memq Function

Syntax:memq object list

The functionmemq 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.

The behavior of this function is equivalent to using the Common Lisp functionmember with a:test argument ofeq and with no:key argument. However,memq demonstrates better performance.

> (memq 1 '(a 1 "b"))
(1 "b")

> (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

parse-body Function

Syntax:parse-body body&optional environment doc-string-allowed-p

The functionparse-body separates the body part of a lambda expression into the following subparts and returns them in the order listed:

This function is useful inside macro definitions that take apart Lisp source code and then recombine it in different ways. It is particularly useful with the&body argument to the Common Lisp macrodefmacro, which is similar to a lambda expression without the explicitlambda designator or a lambda list.

The body argument is a list of executable Lisp forms. This argument generally consists of the body part of a lambda expression or the&body argument todefmacro.

The optional environment argument specifies a lexical environment that might contain local macro definitions.

A non-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.

time1 Macro

Syntax:time1 form

The macrotime1 evaluates the specified form and returns the following information:

Any parameters not available in the implementation are returned asnil.

The results of the evaluation of the form are discarded.

;;; 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 collections

with-interrupts-deferred Macro

with-interrupts-allowed Macro

Syntax:with-interrupts-deferred {form}*

Syntax:with-interrupts-allowed {form}*

These macros determine whether a program can defer asynchronous interrupts:

The body of the macro expansion function is specified by the form arguments. They are executed in order. The value of the last form executed is returned as the result of executing the macro. Any interrupts that occur from within the body ofwith-interrupts-deferred are deferred until the execution of the body is complete.

See Also:interrupt-process, interrupts-deferred-p,with-interruptions-allowed,with-interruptions-inhibited

xor Function

Syntax:xor&rest values

This function is true if an odd number of the specified values are non-nil; otherwise, it is false.

> (xor '3 nil) 
T  

> (xor nil t) T

> (xor (eql 3 4) (> 5 6)) NIL


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker