Closed Mercerenies closed 2 years ago
Following in footsteps somewhat close to Clojure, we've designed a macro called update
. The following are equivalent
(update xyz (+ 1))
(set xyz (+ xyz 1))
and, for syntactic convenience, you are also permitted to use a symbol for unary functions, so the following two are equivalent
(update xyz foobar)
(set xyz (foobar xyz))
Note that this does work with all set
forms, since it's merely a syntactic macro. However, if there are side effects in the xyz
part, they may be evaluated multiple times (current implementation will always evaluate them twice, but I do not guarantee that).
GDScript, of course, has
+=
,-=
, etc. compound assignment operators, which are far more convenient than repeating the name of the thing being assigned to.There is some precedent here. Common Lisp uses
incf
for+=
anddecf
for-=
. We could always define several names, possibly as part of a more generalsetf
interface a la Common Lisp.