Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing without newlines results in incorrect behavior #9

Open
m-chaturvedi opened this issue Apr 20, 2022 · 4 comments
Open

Printing without newlines results in incorrect behavior #9

m-chaturvedi opened this issue Apr 20, 2022 · 4 comments

Comments

@m-chaturvedi
Copy link


$  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
>
@BenBrock BenBrock changed the title Incorrect behavior with newline and templates Printing without newlines results in incorrect behavior Apr 22, 2022
@BenBrock
Copy link
Owner

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
Copy link
Owner

BenBrock commented Apr 22, 2022

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
Copy link
Owner

BenBrock commented Apr 22, 2022

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.

@Starwort
Copy link

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]);)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants