Operational Assignments #23
Labels
feature-request
Any request for a new feature of the language. Includes both syntax and library features.
semantics
Generic label for semantics issues. All semantics issues should have this tag.
syntax
Any issue relating to the syntax of Myst.
Milestone
Operational assignments are common shorthands for "dual expressions", where an operation is performed, and then the result is re-assigned to the same left hand value used in the operation. For example:
For non-logical operations, this is essentially a simple syntax rewrite that takes any expression in the form
a {{op}}= b
and rewrites it asa = a {{op}} b
. This works for all of the arithmetic and comparative operators.However,
||=
and&&=
are generally handled differently, something that the semantics of which are surprisingly complex. I won't bother going into those semantics here, as it could easily take up multiple articles on its own.In any case, the parser is already capable of parsing these statements, and has the corresponding
OpAssign
node to represent them. However, the interpreter does not actually support visiting these nodes, and will instead raise an error when encountered.I would recommend a two-step approach to this, unless the second step becomes more simple.
Implement
OpAssign
for the arithmetic and comparative operators, but raise anUnsupportedError
or similar when encountering||=
or&&=
.Go back and flesh out
||=
and&&=
properly once assignment methods are implemented (rewrites ofobj.method = value
to be equivalent toobj.method=(value)
, wheremethod=
is a method name.The text was updated successfully, but these errors were encountered: