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

print unreadable symbol utilizing #=(symbol ...) for *read-eval* #80

Open
jleonard-r7 opened this issue Mar 2, 2022 · 1 comment
Open

Comments

@jleonard-r7
Copy link

jleonard-r7 commented Mar 2, 2022

with two small tweaks, we could achieve REPL copy/paste-able output a la Python's "repr"

namely, have symbols rendered as:

[:text (str "(symbol \"" x "\")")]

and seqs rendered as:

(pretty-col this "'(" x :line ")" visit)

Any reason (besides annoyance-parity with cljs.pprint/pprint) this wasn't considered?

@brandonbloom brandonbloom changed the title with two small tweaks, we could achieve REPL copy/paste-able output a la Python's "repr" print unreadable symbol utilizing #=(symbol ...) and *read-eval* Mar 3, 2022
@brandonbloom brandonbloom changed the title print unreadable symbol utilizing #=(symbol ...) and *read-eval* print unreadable symbol utilizing #=(symbol ...) for *read-eval* Mar 3, 2022
@brandonbloom
Copy link
Owner

Hey @jleonard-r7, if I understand correctly, what you're asking for here is support for round-tripping of unreadable symbols (ie those with invalid syntax, but valid runtime representations). The round-tripping pair of read and pr in Clojure don't really have an analogous pair in Python. Python's str is similar to Clojure's pr-str, but Python's repr is something like (comp pr-str uneval). That is, it's the inverse of eval, not read. This however is especially tricky and problematic for symbols, because of evaluation rules.

I think what you're really asking for here is support for printing using the semi-secret #= reader form. See *read-eval* as well. In this world, some invalid symbol would be printed like: #=(symbol "namespace with spaces in it" "and/some~invalid(chars)here").

Note that your proposed implementation has numerous problems: consider namespaces, as well as embedded slashes or quote characters in the symbol.

I'm open to the idea of detecting unreadable symbols and fallingback to #_. Maybe, maybe-not guarded by some :print-eval true option. My main concern here is that analyzing a symbol for readability may meaningfully impact performance for large data printing, which is a primary usecase of Fipp.

Given how easy it is to create a new printer (basically just copy/paste/tweak edn.cljc), I'm tempted to close this issue, but I'll leave it open in case anyone wants to attempt this and see how big the code and performance impact is.

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