-
Notifications
You must be signed in to change notification settings - Fork 149
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
Support *print-readably* for Failure and Parser print-method #230
base: master
Are you sure you want to change the base?
Conversation
I'm currently in the process of evaluating instaparse pull requests. Thanks for submitting this. I would appreciate some more background information about what sort of problem you're seeing in a repl with the current behavior, as I haven't seen the issue myself, and I use nREPL via CIDER. My concern with making this change is that print-readably is, by default, true, so this would potentially be a breaking change as it would change the default behavior for everybody. This is not an opt-in modification. This change does indeed break one of the tests in core_test.cljc, specifically the round-trip is defined as follows:
This round-trip definition, in my mind, is the basic promise of printing readably, and instaparse currently fulfills this. For example, in Clojure, if you evaluate Analogously, evaluating an instaparse parser with a REPL using the default clojure printer prints a value that can't be read directly; you or some other process is responsible for wrapping it in a string if you want to work with it as a value. I don't think there's any way for me to modify the built-in clojure reader to support this notation, so the best I can do is guarantee that the string can be read by the I acknowledge there are some limitations to the current print method, for example, the printed output does not capture a parser's desired output format. There is some precedent for that within Clojure, for example, sorted-sets and sets print the same. But for true serialization needs, |
IIRC the main confusion was not about sending over network or escaping. The main problem was trying to understand what did that function actually returned. Normally you can just Alternatively, REPL can always just |
I think I understand your point about the printing making it harder to see exactly what the type is. But the type definitely is there, and the REPL doesn't really seem to have a problem with it as far as I can tell. My CIDER REPL is currently configured to use Clojure's pprint to display REPL output, and so my interaction currently looks like this:
I've never understood why Clojure's pprint doesn't show the type of a record; that's another example of the type not being readily available from printing. But pprint does show you the underlying map, so this is normal pprint behavior. The point here is that overriding the print-method does not really affect any of the other printers, or the REPL's ability to work with the value, as far as I know. I think if I were doing it all over again, I'd be more reluctant to override the default printer, but the advantage is that the output is much easier to understand than the grammar in data form, which doesn't make sense unless you understand the implementation, or at least understand the various combinators that are used to build the parser. Most people seem to like that ease of understanding, rather than being able to see the innards. Probably the error printing is the most valuable, as the linebreaks and whitespaces in the printing places the |
This PD only changes output when you I’m not super invested in this, I already fixed this for myself, so I’ll leave the decision of what’s more important: less unexpected behaviour or backwards compatibility up to you |
This is important for machine-readable REPLs like nREPL and Clojure Sublimed Socket REPL to operate. They have to print values to send them over the network in machine-readable format. Similar to what
prn
does compared toprintln
Before:
After: