defAndCall macro for refactoring

This commit is contained in:
2022-07-27 16:32:16 +00:00
parent 8f58f02ef5
commit 2d53027da3
2 changed files with 23 additions and 6 deletions

View File

@@ -0,0 +1,8 @@
// Quick and dirty way to make a block reusable without restructuring code
// TODO won't work if locals are used in the body
(defMacro defAndCall [type name &body body]
(assert (exprCase type
(function true)
(method true)
(_ false)) "the first argument to defAndCall must be a symbol: function or method")
`{(,type ,name [] ,@body) (,name)})