Changing "add" and "delete" to be expressions rather than statements #3743
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #3684 we discussed (among other things) possible syntax for operations associated with a new
list
container type. The front-runner for popping elements from either the front or the back of alist
is usingdelete
(delete L[0]
for the front anddelete L[-1]
for the back). Since a very common operation would be pop-list-element-and-do-something-with-it, it would be helpful if one could writeelem = delete L[0]
, for example, to pop the front ofL
and return it inelem
. However, to do thatdelete
needs to be an AST expression node. Currently, it's an AST statement node, and those don't have values associated with them.This PR lays the groundwork for such a change. It changes
delete
AST nodes to be expressions that (potentially) return values. For symmetry, because it would be a bit weird to do otherwise, it also likewise changesadd
AST nodes.The question is then what values should these expressions return? This PR kicks that can down the road: they currently behave as "void" types that don't return anything.
While the change is conceptually simple (and backward compatible), it winds up moving a bunch of code from various
Stmt
files intoExpr
files, along with small accompanying tweaks, so quite a bit gets touched even though nothing deep is going on.I've also included two other minor changes. One of these is a bug fix to prevent bad initializers from leading to crashes in some circumstances. The other is to change expressions that render as words to include a space separating that word from their operand. This last (isolated to a separate commit) leads to a bunch of BTest changes that look voluminous but are in fact trivial.