Skip to content

Commit

Permalink
Add do-nothing
Browse files Browse the repository at this point in the history
Closes #159.
  • Loading branch information
ruricolist committed Oct 14, 2023
1 parent d56e6a0 commit 63ed80c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions functions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,17 @@ If there are not VALUES, returns nothing."
(lambda (&rest args)
(declare (ignore args))
(values ,@temps)))))))


(define-compiler-macro do-nothing (&rest args)
`(progn ,@args (values)))

(-> do-nothing (&rest t) (values &optional))
(declaim (inline do-nothing))
(defun do-nothing (&rest args)
"Do nothing and return nothing.
This function is meant as a placeholder for a function argument.
From LispWorks."
(declare (ignore args))
(values))
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
#:fnil
#:mvconstantly
#:fuel
#:do-nothing
;; Trees.
#:reuse-cons
#:car+cdr
Expand Down
8 changes: 8 additions & 0 deletions tests/functions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,11 @@
(let ((fuel (fuel most-positive-double-float)))
(signals error
(funcall fuel double-float-epsilon))))

(test do-nothing ()
(is (null (do-nothing)))
(is (equal '() (multiple-value-list (do-nothing))))
;; Make sure we preserve side effects, in order.
(let ((list '()))
(do-nothing (push 1 list) (push 2 list))
(is (equal list '(2 1)))))

0 comments on commit 63ed80c

Please sign in to comment.