-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Feature request: allow multiple expressions in a single program #697
Comments
Well, actually this is possible right now as well if let x = 42;
let y = 42;
x * y We can improve lexer and allow |
Yes, I know, but the real program looks more like this:
I guess I can rewrite it like this, but it is not as readable and debuggable:
|
I see. So, this request to add statements to Expr. I think this is nice to add via option: |
Maybe, but I explicitly say that "everything is an expression" so :) If we take switch in account, would it be a statement or an expression? I believe it should be an expression or it probably would not fit into the existing purpose of the language. And if |
Statements support(or using assert(status_code == 0);
assert(status_message == "");
// normal expr stuff
1 + 1 Currently it's possible to work around this by
- func assert(condition bool)
+ func assert(condition bool) any // always returns nil
let _s1 = assert(status_code == 0);
let _s2 = assert(status_message == "");
// normal expr stuff
1 + 1 |
TLDR The following program should be a valid expr:
It should work like Ruby, where everything is an expression and the last expression is used as the result. Given that it works fairly well for Ruby, I guess expr-lang can be modeled just like it.
Currently what we do in Uptrace transformations, is just split the multi-line expressions into individual programs and then run them one by one. It works so far, but variables don't survive between programs and the performance is probably sub-optimal since each program requires a separate
VM
.I believe OpenTelemetry does the same with multi-line OTTL so they would probably benefit as well.
A more realistic example what multi-line expressions can achieve:
The text was updated successfully, but these errors were encountered: