defAndX for local form versions

This commit is contained in:
2022-08-21 17:20:24 +00:00
parent 888d0b2178
commit 91d3d73665

View File

@@ -1,15 +1,14 @@
// Quick and dirty way to make a block reusable without restructuring code // Quick and dirty way to make a block reusable without restructuring code
// TODO won't work if locals are used in the body // TODO won't work for function/method if locals are used in the body
(defMacro defAndCall [type name &builder b &body body] (defMacro defAndCall [type name &builder b &body body]
(assert (exprCase type (assert (exprCase type
(function true) ((exprOr function method localFunction) true)
(method true) (_ false)) "the first argument to defAndCall must be a symbol: function, method, or localFunction")
(_ false)) "the first argument to defAndCall must be a symbol: function or method")
`{(,type ,name [] ,@body) (,(b.symbol (symbolNameValue name true true)))}) `{(,type ,name [] ,@body) (,(b.symbol (symbolNameValue name true true)))})
// Quick and dirty way to define constants without restructuring code // Quick and dirty way to define constants without restructuring code
(defMacro defAndReturn [type name value &builder b] (defMacro defAndReturn [type name value &builder b]
(assert (exprCase type (assert (exprCase type
((exprOr var prop) true) ((exprOr var prop localVar) true)
(_ false)) "the first argument to defAndReturn must be a symbol: var or prop") (_ false)) "the first argument to defAndReturn must be a symbol: var, prop, or localVar")
`{(,type ,name ,value) ,(b.symbol (symbolNameValue name true true))}) `{(,type ,name ,value) ,(b.symbol (symbolNameValue name true true))})