-
Notifications
You must be signed in to change notification settings - Fork 17
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
Importing a library changes read syntax #433
Comments
Well, |
The idea (not sure that it is a good one) is to have a better message when using bad sharp syntaxes. We have: stklos> #s16
**** Error:
%read: bad sharp syntax in `"#s16"'
stklos> (import (srfi 4))
stklos> #s16
**** Error:
%read: bad uniform vector specification `s16' Furthermore, defining a constant without the primitives to access its content is probably not very helpful. Anyway, changing that point is easy. Do you see any drawback to the current implementation? |
BTW @lassik, what are the bugs you have seen with the current implementation? |
The first bug is the above:
Since the reader does not recognize the The second bug is:
Any numeric vector prefix can be used to read the |
This may require special handling when reading from a terminal (as opposed to a file)? |
I think the second bug doesn't happen anymore - am I wrong?
|
And I'm not sure it's possible to fix the second one... The reader sees
will, in most schemes(*), print "a", then trigger an exception and print the error message, and then print "b"... So errors like that won't make the reader stop -- the behavior of STklos for sharp syntax seems OK, I guess. (*) Kawa stops at the error. The Chez REPL expects the user to hit enter for each expression entered, so it's totally different. The others I tried behave as I mentioned Also, I see that only STklos and Chicken implement SRFI 207, and Chicken does not implement the sharp syntax part. |
You could first read all available input from the terminal into a buffer. Then |
I.e. something like this pseudo-code: while (terminal_fd_is_not_closed) {
buffer_clear();
while (poll(terminal_fd)) {
char input_char[1];
read(terminal_fd, input_char, 1);
buffer_putc(input_char);
}
try {
input_port = make_string_input_port(buffer);
while (datum = read_scheme_datum(input_port)) {
eval(datum);
}
} except {
display_error();
} finally {
close(input_port);
}
} |
But the same code that reads from a terminal reads from a string. Maybe it's possible to make STklos ignore what happens post-error in a whole line, I guess. A read error would make it go all the way out to the point where it processed the whole line. Not sure. |
See that partial expressions may be passed in a line (a string):
I don't remember how STklos deals with this, but you can take a look at |
Reading until end-of-line is not the best way to do it. If you paste 50 lines of code into a terminal, and the 5th line raises an error, then the interpreter will continue to process the next 45 lines. It should not do that. It's better to read with a timeout. IIRC the conventional timeout for reading from a TTY is something like 50 milliseconds. If you paste a lot of text into a terminal window, the terminal emulator will send it all instantly to the program running in the terminal. So the program will receive all the pasted text, and no more, if you use a reasonable timeout. |
In other words:
|
It's probably good to add some extra logic to that, so that a partial line is never read and evaluated, even if it comes within the timeout. |
What causes the following?
#u16(...)
syntax does not work:Import the right SRFI, and it does:
As far as I know, read syntax is only supposed to be changed by
#!
directives (e.g.#!r6rs
or#!fold-case
). Imports do not normally change it.The text was updated successfully, but these errors were encountered: