read_line doesn't work in the interpreter
akaiDing opened this issue · 3 comments
Here's the example:
! read_line
hello
After I type anything on it, the interpreter got stuck and doesn't work and return anything >_<.
Addressed in 799802d. Note that the expected behavior has been changed. See https://github.com/zydeco-lang/zydeco/blob/main/zydeco/new_echo.zydeco for an example:
! read_line { fn (input: String) -> ! write_line input { ! exit 0 } }
Note that the repl style is not supported to the best at the moment because we are experiencing changes in the form of main program, but we haven't generalized it to be usable in all platforms.
Currently we are focusing on unix style programs, which means every program must end with an ! exit <return int>
similar to what a unix process would behave. Said computation has type OS
, which is a computation type, and THE type for our main program.
At this moment, ! exit <return int>
would call std::process::exit
, which effectively ends our program. Therefore, it's recommended to use alias zydeco="cargo run --bin zydeco --"
to get a zydeco
shorthand, and zydeco run <path_to_file>
to try small programs out.
Closing as the original issue is fixed, but as @LighghtEeloo mentions the only way to write a program that does I/O in the repl is either an infinite loop or exit the process, but that should be fixed soon when we virtualize the evaluator.