evcxr / evcxr

Other
5.5k stars 217 forks source link

Where are the errors and print! not working #157

Closed Tros-t closed 2 years ago

Tros-t commented 3 years ago

Hi, Loved the main thing but I cannot see my errors when I run a = 5 without defining a it doesn't gives me any error just prints 5 out.

And when I try to print something without the ln or just print!("hi"); it doesn't print anything to the output area.

And do you guys have any ideas to make this a bit faster

bjorn3 commented 3 years ago

print!() without ln doesn't flush the stdout buffer. libstd only writes to the OS stdout every time it sees a newline. That is stdout is line buffered.

davidlattimore commented 3 years ago

Thanks for the report @Saad-py. That's interesting that a=5 doesn't error. What's happening is that because it doesn't end in a semicolon, it's treated as an expression and evcxr tries to print expressions. You can imagine it taking your code and wrapping it as println!("{}", a = 5);... which compiles. I think in order to make this code produce an error, I'd probably need to explicitly check for it.

But rest assured, errors should in general be displayed. For example if you do a = 5; then you get:

>> a = 5;
   ^ not found in this scope
cannot find value `a` in this scope
bjorn3 commented 3 years ago

Could you write println!("{}", &(a=5)); ibstead of println!("{}", a=5); for a=5? That should avoid interpreting a= by println!() instead of as assignment.

davidlattimore commented 2 years ago

With the above commit, an error is now show as expected.

>> a = 5
   ^ not found in this scope
cannot find value `a` in this scope