Common Lisp Package: REASONABLE-UTILITIES.SYNTAX

Syntax extensions.

README:

FUNCTION

Private

EXTRACT-FUNCTION-NAME

Useful for macros that want to mimic the functional interface for functions like #'eq and 'eq.

Undocumented

EXPAND-BINDING

EXPAND-DESTRUCTURING-CASE

EXPAND-PREDICATE-CASE

GENERATE-SWITCH-BODY

MACRO

Public

BIND ((&REST BINDINGS) &BODY BODY)

Bind variables from BINDINGS to be active inside BODY, as if by LET*, combined with MULTIPLE-VALUE-BIND, DESTRUCTURING-BIND and other -bind forms, depending on the type of the first argument.

CSWITCH (&WHOLE WHOLE (OBJECT &KEY (TEST 'EQL) (KEY 'IDENTITY)) &BODY CLAUSES)

Like SWITCH, but signals a continuable error if no key matches.

DCASE (KEYFORM &BODY CLAUSES)

DCASE is a combination of CASE and DESTRUCTURING-BIND. KEYFORM must evaluate to a 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-test (x) (dcase 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-test (list :foo 1 2)) ; => "foo: 1, 2" (dcase-test (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (dcase-test (list :alt1 1)) ; => "alt: 1" (dcase-test (list :alt2 2)) ; => "alt: 2" (dcase-test (list :quux 1 2 3)) ; => "unknown: 1, 2, 3" (defun decase-test (x) (dcase 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-test (list :foo 1 2)) ; => "foo: 1, 2" (decase-test (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (decase-test (list :alt1 1)) ; => "alt: 1" (decase-test (list :alt2 2)) ; => "alt: 2" (decase-test (list :quux 1 2 3)) ; =| error

DCCASE (KEYFORM &BODY CLAUSES)

DCCASE is a combination of CCASE and DESTRUCTURING-BIND. KEYFORM must evaluate to a 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 dccase-test (x) (dcase 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-test (list :foo 1 2)) ; => "foo: 1, 2" (decase-test (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (decase-test (list :alt1 1)) ; => "alt: 1" (decase-test (list :alt2 2)) ; => "alt: 2" (decase-test (list :quux 1 2 3)) ; =| continueable error

DECASE (KEYFORM &BODY CLAUSES)

DECASE is a combination of ECASE and DESTRUCTURING-BIND. KEYFORM must evaluate to a 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 decase-test (x) (dcase 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-test (list :foo 1 2)) ; => "foo: 1, 2" (decase-test (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (decase-test (list :alt1 1)) ; => "alt: 1" (decase-test (list :alt2 2)) ; => "alt: 2" (decase-test (list :quux 1 2 3)) ; =| error

DOTABLE ((K V TABLE &OPTIONAL REZ) &BODY BODY)

Like DOLIST but iterates over key-value pairs (K V) in anything, that can be viewed as a table (hash-table, alist, plist, object).

ESWITCH (&WHOLE WHOLE (OBJECT &KEY (TEST 'EQL) (KEY 'IDENTITY)) &BODY CLAUSES)

Like SWITCH, but signals an error if no key matches.

MULTIPLE-VALUE-PROG2 (FIRST-FORM SECOND-FORM &BODY FORMS)

Evaluates FIRST-FORM, then SECOND-FORM, and then FORMS. Yields as its value all the value returned by SECOND-FORM.

PCASE (PRED KEYFORM &REST CLAUSES)

Like CCASE, but uses given PRED instead of EQL to select appropriate CLAUSE. Example usage: CL-USER> (pccase '< 1 (0 (print "Below zero")) (2 (print "OK")))

PECASE (PRED KEYFORM &REST CLAUSES)

Like ECASE, but uses given PRED instead of EQL to select appropriate CLAUSE. Example usage: CL-USER> (pecase '< 1 (0 (print "Below zero")) (2 (print "OK")))

SWITCH (&WHOLE WHOLE (OBJECT &KEY (TEST 'EQL) (KEY 'IDENTITY)) &BODY CLAUSES)

Evaluates first matching clause, returning its values, or evaluates and returns the values of DEFAULT if no keys match.

GENERIC-FUNCTION

Public

Undocumented

BIND-DISPATCH (ARG &REST ARGS)

Private

Undocumented

CASE-FAILURE-NAME (CONDITION)

CASE-FAILURE-POSSIBILITIES (CONDITION)

CONDITION

Private

Undocumented

CASE-FAILURE