Is StreamInstance::Null like /dev/null on Linux?
When Machine is reset(), the current stream is set to stdin, why? What happen if the input stream was a file?
It could be. Currently trying to Read or Write from a null stream results in an error. Its purpose for now is to be targeted by copy_term whenever an attempt to copy a stream is made.
reset() restores the machine to its default state, which reads input from stdin. If the current input stream was previously a file, then it's the user's responsibility to close it, if there's a still a handle to it somewhere. If the stream passes from the WAM and is destroyed, RAII will close it automatically from the file's Drop instance.
Code like this one doesn't compile:
let input_stream = Stream::from(String::new());
let output_stream = Stream::from(String::new());
let input_stream2 = Stream::from(String::new());
println!("input: {:?}", input_stream);
println!("output: {:?}", output_stream);
let mut wam = Machine::new(input_stream, output_stream);
wam.current_input_stream = input_stream2; // Error.
It states thatcurrent_input_stream is a private field.
The visibility of some types, member variables, ... need to change for the code to compile.
Why are you trying to assign to it from outside of the WAM?
I didn't find a method to change the stream of the WAM, so direct access is one way to change it.
Changing the stream isn't the end goal but it isn't possible and it isn't possible to access it either.
I would like to automate some tests.
In that case, you could write a getter function in machine/mod.rs for the current input stream, and add the #cfg[test] attribute so that it's only compiled for the test suite.
It should work. Is there going to be a way to change/access the internal parts of the WAM that's not for tests only? For an user (application programmer), only the binary scryer-prolog can be used, unless deep changes in the code are done.
I'm not sure I entirely understand your question. Are you asking if the WAM internals could be made into a library for use by another Rust application, meaning the cross-module permissions would have to change?
If this crate becomes a library then the WAM internals will be exposed somehow (changing cross-module permissions or adding some getters/setters).
To automate some tests the idea was to read a file, execute the code with :- initialization(test) and retrieve the result then assert, source like file src/test.rs, but it doesn't work.
@notoria: For testing, it would be tremendously useful to specify goals on the command line, please see #187.
Being able to run Scryer with
$ scryer-prolog -g run file.pl
to invoke run/0 in file.pl would nicely solve this issue.
Handling a failing test case could also be done on the command line:
$ scryer-prolog -g "( run -> true ; write(failed), nl ), halt" file.pl
I would greatly appreciate if you could look into this, if you are interested, because this would make it possible to use the same file to run multiple different test cases, flexibly in scripts.
One alternative is to make the test case invoke read/1 to read a goal, and then use call/1 to invoke it. For example:
?- read(G), G. true. + RET G = true.
Closing this issue, the main questions was answered.