New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support capture existence testing and simple control flow #15
Conversation
A fairly straightforward implementation. Rather than draining the entire list of parameters from `exec.function_parameters` when calling a function, we just drain the last `N` where `N` is the number of arguments passed to the function. The added test (hopefully) demonstrates that this works correctly. Without the changes in this PR, execution would panic when the outer `replace` call was called without arguments (as these would have been purged by the second call).
Adds the prefix operator `?` which coerces capture existence/non-existence into a boolean value. Thus, `? @foo` is `#true` if the capture `@foo` exists, and is `#false` otherwise. Because a capture that _doesn't_ exist results in an error if evaluated, this behaviour cannot be implemented in terms of the existing function call mechanism. The syntax itself is also not entirely ideal. For ease of parsing, it's better for it to be a prefix operator, but `?@foo` is not the prettiest combination of symbols. Alternatively, one might dispense with the `@` in this expression, and write it simply as `?foo`, though that might cause confusion if there is also a local variable called `foo` in the given stanza.
Adds the functions `and`, `or`, and `not` to the standard library. The first two of these accept any number of arguments. The third expects a single argument.
As an fyi @hendrikvanantwerpen has also been working on lazy evaluation in the |
Yep, I'm aware (though that branch doesn't seem to be in a good state for reviewing yet, so I haven't looked at its contents in any detail). The way I see it, this PR is just a proposal. I'm personally not enthused with the |
Agreed! Closing. |
Adds support for
if
statements and a prefix operator?
that can be used to test for the presence of a given capture.Thus, a stanza like
will set the
first_expr
attribute only in the case where the first statement in the input is in fact an expression.In addition to this, this PR also adds functions for the usual boolean operators
and
,or
, andnot
.Can be reviewed commit-by-commit.