diff --git a/functions.lisp b/functions.lisp index a04b7d026e1870a4da0c92c8dad68fb2a0d5a4d7..dd83e38b4ebc64ab566c0d0775fabd53025a9f61 100644 --- a/functions.lisp +++ b/functions.lisp @@ -158,4 +158,4 @@ with and ARGUMENTS to FUNCTION." "Expands into a lambda-expression within whose BODY NAME denotes the corresponding function." `(labels ((,name ,lambda-list ,@body)) - #',name)) \ No newline at end of file + #',name)) diff --git a/hash-tables.lisp b/hash-tables.lisp index 3a6c3eb561c7e498bb2b114b0f093e4d4d59582e..f461a7035f0205ff45015e4fce8098669ec2c34f 100644 --- a/hash-tables.lisp +++ b/hash-tables.lisp @@ -1,5 +1,16 @@ (in-package :alexandria) +(defmacro ensure-gethash (key hash-table &optional default) + "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT +under key before returning it. Secondary return value is true if key was +already in the table." + (once-only (key hash-table) + (with-unique-names (value presentp) + `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table) + (if ,presentp + (values ,value ,presentp) + (values (setf (gethash ,key ,hash-table) ,default) nil)))))) + (defun copy-hash-table (table &key key test size rehash-size rehash-threshold) "Returns a copy of hash table TABLE, with the same keys and values @@ -88,14 +99,3 @@ PLIST. Hash table is initialized using the HASH-TABLE-INITARGS." ((not tail)) (setf (gethash (car tail) table) (cadr tail))) table)) - -(defmacro ensure-gethash (key hash-table &optional default) - "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT -under key before returning it. Secondary return value is true if key was -already in the table." - (once-only (key hash-table) - (with-unique-names (value presentp) - `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table) - (if ,presentp - (values ,value ,presentp) - (values (setf (gethash ,key ,hash-table) ,default) nil)))))) diff --git a/sequences.lisp b/sequences.lisp index ef594dd6eb8e4be2a134ebcdf442404a59491f9d..118322ab5c54ce6f633b36fa243c9c3fffd1a8c3 100644 --- a/sequences.lisp +++ b/sequences.lisp @@ -135,7 +135,7 @@ are not proper bounding index designators for SEQUENCE." (defun remove/swapped-arguments (sequence item &rest keyword-arguments) (apply #'remove item sequence keyword-arguments)) -(define-modify-macro removef (item &rest remove-keywords) +(define-modify-macro removef (item &rest keyword-arguments) remove/swapped-arguments "Modify-macro for REMOVE. Sets place designated by the first argument to the result of calling REMOVE with ITEM, place, and the REMOVE-KEYWORDS.") @@ -144,7 +144,7 @@ the result of calling REMOVE with ITEM, place, and the REMOVE-KEYWORDS.") (defun delete/swapped-arguments (sequence item &rest keyword-arguments) (apply #'delete item sequence keyword-arguments)) -(define-modify-macro deletef (item &rest remove-keywords) +(define-modify-macro deletef (item &rest keyword-arguments) delete/swapped-arguments "Modify-macro for DELETE. Sets place designated by the first argument to the result of calling DELETE with ITEM, place, and the REMOVE-KEYWORDS.")