I think the problem is not really evaluating Rust code on the fly: you could just as well compile it on the fly and execute is, this is what the Haskell interpreter ghci does.
The difficulty is more in defining what it means to enter code one line at a time, what about context, scope, lifetimes, all these stuff.
If a more knowledgeable Rust team member can confirm…
I think some of the typing would be problematic, as it allows action at a distance.
e.g.
fn bar(i : &u16) {
i + 1;
}
let a = 8; // a is a u8.
bar(&a); // Now a needs to be a u16,
// but we executed the line of code
// above, which forced it to be u8.
// Is this a type error?
You can probably solve this, by requiring all blocks of code to be executed repl style to be standalone.
i.e. the above code is entered as:
fn bar(i : &u16) {
i + 1;
}
## Execution happens in the REPL
{
let a = 8;
bar(&a);
}
## Execution happens in the REPL.
And make the far above give "a not defined in this scope"
The difficulty is more in defining what it means to enter code one line at a time, what about context, scope, lifetimes, all these stuff.
If a more knowledgeable Rust team member can confirm…