Comments (4)
from rhai.
so this works, but without introducing a ()
type into the script engine we can end up in some weird states. a loop {} may not always return something, there's no enforcement of consistency at this point. for instance a while loop like this:
let i = 0;
while i < 100 {
if i == 50 { break true; }
i+=<user input>;
}
depends on the user input to increment. if it never hits 50, the loop returns with () at the end which the engine doesn't really know how to gracefully handle. something like this is a simpler example:
> let x = while true == false { break; }
> print(x)
error: Function argument types do not match
while this works as expected:
> let x = while true == true { break 7 }
> print(x)
7
If anyone has ideas other than me implementing a () type, i'd love to hear them!
from rhai.
I'm wondering whether this is really necessary, as it is just as easy to write:
let x;
loop {
// complicated computations
x = 7;
break;
};
This way, statements such as while
, loop
, for
etc. do not need to be turned into valid expressions, avoiding some weird-looking scripts like let x = while true == true { break 7 };
.
For Rust, it is actually useful because you need not make x
mutable if you create it directly from the loop. However, Rhai variables are mutable by default and opt-out by const
.
from rhai.
I'm closing this one unless that are new opinions.
from rhai.
Related Issues (20)
- Problem compiling 1.16 HOT 4
- Clippy warning `needless-pass-by-ref-mut` by `codegen` HOT 1
- Array support in scope HOT 9
- Function parameters and serde HOT 3
- Packing Rhai into 128KB under no-std on STM32 HOT 17
- Can't sort array by string (using closure) HOT 4
- Object `to_json` produces invalid JSON when the `metadata` feature is not enabled HOT 3
- array.index_of: string argument got mistaken as function? HOT 3
- Possible memory leak HOT 4
- Support for builder pattern? HOT 14
- Possible to create AST at compile-time? HOT 1
- smartstring is unsound and has UB HOT 1
- Tracking issue for CustomType derive macro HOT 8
- Undocumented breaking change in v1.17.0 HOT 9
- Can't use older Rhai versions anymore HOT 17
- Panic: Entered unreachable code when using Dynamic::into_shared() HOT 5
- Error position for "Function not found" on operators points to first operand HOT 4
- Error including wasm-bindgen feature in a workspace crate. HOT 4
- Feature: syntax `str[range]` support like rust string indexing by range HOT 5
- Registered enum types can't be used with assert_eq in Rhai HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rhai.