Skip to content

Instantly share code, notes, and snippets.

@hidsh
Last active April 4, 2023 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidsh/173c21f083637766657398559fbb7be2 to your computer and use it in GitHub Desktop.
Save hidsh/173c21f083637766657398559fbb7be2 to your computer and use it in GitHub Desktop.
my assersion macro
;; 関数のトップレベルでしか動作しないので注意
(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))))
;; 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