Last active
April 4, 2023 18:53
-
-
Save hidsh/173c21f083637766657398559fbb7be2 to your computer and use it in GitHub Desktop.
my assersion macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 関数のトップレベルでしか動作しないので注意 | |
(defmacro my-assert (form) | |
`(let* ((backtrace (backtrace-frame 2)) | |
(func-name (nth 1 backtrace))) | |
(unless ,form (error "Assert in %s(): should be %S" func-name ',form)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; test func | |
(defun test1(n) | |
(my-assert (< n 100)) | |
'ok) | |
(defun test2(s) | |
(my-assert (stringp s)) | |
'ok) | |
;; try test | |
(test1 100) | |
; => "Assert in test1(): should be (< n 100)" | |
(test1 99) | |
; => ok | |
(test2 999) | |
; => "Assert in test2(): should be (stringp s)" | |
(test2 "xxx") | |
; => ok | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment