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

Proposal: Split eval output #133

Open
acook opened this issue Jan 29, 2024 · 3 comments
Open

Proposal: Split eval output #133

acook opened this issue Jan 29, 2024 · 3 comments

Comments

@acook
Copy link

acook commented Jan 29, 2024

If we split the printed output from the value output when the program is run it would allow the return value to be distinct from any online output and format them independently.

Issues

Colors from print bleed into results

Given:

println!("\x1b[31mHello World!"); 5 + 5

Then the output is all red until the next In: prompt.

Values cannot be formatted differently than the printed out

print!("foo")

Outputs:

out: foo()

But a better format might be:

foo
result: ()

This would bring IRust closer in line with other REPL formatting.

Solutions

Since we already need to capture the output to display it anyway, it should be simple enough to send the return value to a different location, such as a separate pipe, or after a simple delimiter.

Delimiter

Before the value is printed, include a simple delimiter. Even just --- and then split the text at the last one.

Pipe

Send the value to a pipe that the parent program watches.

@sigmaSd
Copy link
Owner

sigmaSd commented Jan 31, 2024

Hello, thanks your interest

Unfortunately, to do this we need to analyze the code provided by the user, which is not possible currently since we're just sticking the code in a binary and running it

A workaround is to write a plugin, that looks for print statements in the code , and put them last as you described, this won't work in all cases that's why it belongs into the plugins not in the main binary
https://github.com/sigmaSd/IRust/blob/master/SCRIPTS.md

@acook
Copy link
Author

acook commented Jan 31, 2024

Hmm. I assumed it would be possible to not change the user's code at all, except for the final line, which I assume is already happening in order to print the output.

Something like this:

user code
user code
capture_variable = user code (final expression)
print ---
print capture-variable

But I took a look at the code and it is quite different from the other compiled-language REPLs I've played with, so I am probably missing something.

@sigmaSd
Copy link
Owner

sigmaSd commented Jan 31, 2024

If you have an example of a compiled language repl that does this I can take a look at it to see if there's something I can do here

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

2 participants