-
Notifications
You must be signed in to change notification settings - Fork 9
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
Define and implement an array repetition operator #329
Conversation
firebase-deployment for d89b908 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, thank you so much. a couple of doc nits, otherwise really clear.
All fixed and pushed. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks still great to me. just a question around negative repetition counts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some small things, overall lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still 💚
do not merge label because I need to squash in the fixup commits before merging. I've forgotten to do that before, so this may help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Allow the `*` operator to be used on arrays with a number on the right-hand side to repeat an array a number of times, producing an array of the same type with repeated elements. This allows for creating arrays of variable length without needing to write a loop. e.g. n := 4 a := [0] * n will produce `[0 0 0 0]`. There can be any number of elements in the array and they will all be repeated. e.g. `[1 2] * 2` == `[1 2 1 2]`. Update the spec to document this. Add an example to `syntax_by_example.md` Gen-command: make doc docs
Implement construction of arrays via array repetition, a `BinaryExpr` with an array value on the left and a number on the right. The result is the left array repeated the right number of times. Zero times results in an empty array. A non-integer value results in an error. Add test cases for all distinct cases - basic, zero, precedence, variable and error.
Implement construction of arrays via array repetition, similar to the evaluator. A new opcode, `OpArrayRepeat` is added for this operation which the compiler emits based on the types of the arguments to the `*` binary operator. Add tests for some basic cases and the error case. Disable some lint errors due to "complex" code. `vm.Run()` already disabled one, but now there's another. The test case is not really even complex. Stupid linters.
Define the
array * num
operator to repeatarray
num
number oftimes. This allows for easy initialisation of variable sized arrays
without needing to use a loop to do so.
Update the spec with a definition of the operator. Update
syntax_by_example.md
to give some basic examples.Implement this in the evaluator and the bytecode compiler/vm.
Issue: evylang/todo#101