reple icon indicating copy to clipboard operation
reple copied to clipboard

Printing without newlines results in incorrect behavior

Open m-chaturvedi opened this issue 2 years ago • 4 comments


$  reple -env cxx
> $template <typename X> void id(X s) { std::cout << s; }$
> id("Hello");
Hello
> id(2);
> id("Hello");
>

Works fine with endl

$  reple -env cxx
> $template <typename X> void id(X s) { std::cout << s << std::endl
; }$
> id("Hello");
Hello
> id(34);
34
> id("Hey");
Hey
> id(4354);
4354
>

m-chaturvedi avatar Apr 20 '22 08:04 m-chaturvedi

Thanks for creating this issue. This is a result of the design of reple, which currently prints new lines of output. This means that if new output appears without a newline, there is incorrect output.

BenBrock avatar Apr 22 '22 22:04 BenBrock

There's a feature already in repl, line epilogues, that could potentially fix this by adding a newline at the end of each line. There's a question about whether this is the correct thing to do, though, since ideally you would print without a newline, since there is no newline.

There's an example of how to use line epilogues here in the MPI config.

BenBrock avatar Apr 22 '22 22:04 BenBrock

Also, someone emailed me with a potential fix to nondeterministic output, which is related, and could potentially provide a full fix here. This would involve printing out tags before and after each command in order to help determine which command produced which specific bits of output. This way, even if the number of lines of output produced by previously entered commands changes, we can still only print the output produced by the most recently entered command.

This could introduce considerable complexity, though, so if someone wants to tackle this, please discuss here so we can agree on an approach before you write too much code. That way we can keep the code complexity as low as possible.

BenBrock avatar Apr 22 '22 22:04 BenBrock

Related: Printing to stderr results in the last line of stdout being repeated, instead of the line in stderr being printed (example below) image (My last print was a printf("%s\n", argv[0]);)

Starwort avatar Apr 23 '22 21:04 Starwort