Quickutilβ

Lisp utilities on demand

Fork me on GitHub
search

There are 5 utilities.

with-gensyms v1.0

Binds each variable named by a symbol in names to a unique symbol around forms. Each of names must either be either a symbol, or of the form:

(symbol string-designator) 

Bare symbols appearing in names are equivalent to:

(symbol symbol) 

The string-designator is used as the argument to gensym when constructing the unique symbol the named variable will be bound to.

Provides
with-gensymswith-unique-names
Requires
string-designator
Source Code
 
once-only v1.0

Evaluates forms with symbols specified in specs rebound to temporary variables, ensuring that each initform is evaluated only once.

Each of specs must either be a symbol naming the variable to be rebound, or of the form:

(symbol initform) 

Bare symbols in specs are equivalent to

(symbol symbol) 

Example:

(defmacro cons1 (x) (once-only (x) `(cons ,x ,x)))  
  (let ((y 0)) (cons1 (incf y))) => (1 . 1) 
Provides
once-only
Requires
make-gensym-list
Source Code
 
parse-body v1.0

Parses body into (values remaining-forms declarations doc-string). Documentation strings are recognized only if documentation is true. Syntax errors in body are signalled and whole is used in the signal arguments when given.

Provides
parse-body
Source Code
 
parse-ordinary-lambda-list v1.0

Parses an ordinary lambda-list, returning as multiple values:

  1. Required parameters.

  2. Optional parameter specifications, normalized into form:

(name init suppliedp)

  1. Name of the rest parameter, or nil.

  2. Keyword parameter specifications, normalized into form:

((keyword-name name) init suppliedp)

  1. Boolean indicating &allow-other-keys presence.

  2. &aux parameter specifications, normalized into form

(name init).

  1. Existence of &key in the lambda-list.

Signals a program-error if lambda-list is malformed.

Provides
parse-ordinary-lambda-list
Requires
simple-program-error, ensure-list, make-keyword
Source Code
 
destructuring-case v1.0

destructuring-case, 'destructuring-ccase and 'destructuring-ecase are a combination of case and destructuring-bind. keyform must evaluate to af cons.

Clauses are of the form:

((case-keys . destructuring-lambda-list) form*) 

The clause whose case-keys matches car of key, as if by case, ccase, or ecase, is selected, and forms are then executed with cdr of key is destructured and Bound By The destructuring-lambda-list.

Example:

(defun dcase (x)  
  (destructuring-case x  
    ((:foo a b)  
     (format nil "foo: ~S, ~S" a b))  
    ((:bar &key a b)  
     (format nil "bar, ~S, ~S" a b))  
    (((:alt1 :alt2) a)  
     (format nil "alt: ~S" a))  
    ((t &rest rest)  
     (format nil "unknown: ~S" rest))))  
 
 (dcase (list :foo 1 2))        ; => "foo: 1, 2"  
 (dcase (list :bar :a 1 :b 2))  ; => "bar: 1, 2"  
 (dcase (list :alt1 1))         ; => "alt: 1"  
 (dcase (list :alt2 2))         ; => "alt: 2"  
 (dcase (list :quux 1 2 3))     ; => "unknown: 1, 2, 3"  
 
(defun decase (x)  
  (destructuring-case x  
    ((:foo a b)  
     (format nil "foo: ~S, ~S" a b))  
    ((:bar &key a b)  
     (format nil "bar, ~S, ~S" a b))  
    (((:alt1 :alt2) a)  
     (format nil "alt: ~S" a))))  
 
 (decase (list :foo 1 2))        ; => "foo: 1, 2"  
 (decase (list :bar :a 1 :b 2))  ; => "bar: 1, 2"  
 (decase (list :alt1 1))         ; => "alt: 1"  
 (decase (list :alt2 2))         ; => "alt: 2"  
 (decase (list :quux 1 2 3))     ; =| error 
Provides
destructuring-casedestructuring-ccasedestructuring-ecase
Requires
once-only
Source Code