-
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
Refactoring the sharp # reader #434
Comments
I'm not particularly proud of the reader code, and your proposition would probably make it clearer.
Of course! |
I know this would be too complex maybe, but... I the C reader could be configured to optionally call a Scheme procedure, we could implement Scheme reader macros easily. :) |
In theory, the C reader only needs to handle the syntax needed to bootstrap a reader written in Scheme. |
Yes - but I suppose it would be nice to have the core of it still in C, for performance... Then the user (or libraries) could extend it in Scheme, maybe. |
Sounds reasonable. |
STklos also has
And keywords: |
If we implement all of those in C, there's almost nothing left to be implemented in Scheme. Maybe the numeric vectors, fancy comments, etc. |
And user-defined macros. I was thinking of a fast sharp-syntax for those already mentioned, and a configurable reader macro system similar to Common Lisp reader macros, for the user :) and for libraries maybe. But this is just me thinking aloud. @egallesio what do you think? |
Use the new C hash tables for the implementation.
Hi @lasik, One year later 😏 , I have done something similar to what you proposed. The sharp reader can even be extended in Scheme ( I have still to write some documentation about this point). This is done with the (%add-sharp-reader #\o
(lambda (port)
(let ((v (read port)))
(if (eq? v 'one)
1
(error "bad constant #o~a" v))))) permits to return 1 when we encounter The following code has been used to implement the bitvector (%add-sharp-reader #\*
(lambda (port)
(let* ((v (read port))
(str (symbol->string v)))
(or (string->bitvector (string-append "#" str))
(error "bad bitvector #~a" v))))) |
The
#
and#!
reader inread.c
has at least two bugs, which seem to be oversights due to the messy code.Looking at the code, it could be clarified if we used:
#u32
instead ofu
)Here's a quick sketch of how it could look:
Would you accept a PR to do a refactoring like this?
Note that the
#!
keywords can be in the same lookup table as the plain#
words. Due to binary search, there is no performance penalty (arguably not even with linear search).The text was updated successfully, but these errors were encountered: