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

Consider eliding reader produced metadata #90

Closed
lread opened this issue Jan 22, 2021 · 0 comments
Closed

Consider eliding reader produced metadata #90

lread opened this issue Jan 22, 2021 · 0 comments

Comments

@lread
Copy link
Collaborator

lread commented Jan 22, 2021

Adapated from lread/rewrite-cljc-playground#63, fix to be reapplied to rewrite-clj

Problem/Opportunity
Rewrite-clj and therefore rewrite-cljc automatically coerces metadata to nodes.

When the metadata comes from the reader rather than the actual source code, this might cause confusion (see #37).

For example in Clojure, :line and :column metadata are added to quoted lists:

> clj
Clojure 1.10.1
user=> (meta '(1 2 3))
{:line 1, :column 8}

This metadata is not in the original source code. It is added by the reader.

A more obscure use case is under sci (and therefore also babashka).
Sci adds positional metadata :line, :column, :end-line and :end-column to all elements that accept metadata.

> bb --repl
Babashka v0.2.3 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (meta '(1 2 3))
{:line 1, :column 7, :end-line 1, :end-column 15}
user=> (meta [4 5 6])
{:line 3, :column 7, :end-line 3, :end-column 14}
user=> (meta #{1 2 3})
{:line 5, :column 7, :end-line 5, :end-column 15}
user=> 

For rewrite-cljc, this metadata manifests itself problematically during coercion from Clojure form to rewrite-cljc node.

Proposed Solution
I think that suppressing well known reader metadata by default would be less surprising to users of rewrite-cljc.

This is technically a breaking change in default behavior. I can only imagine existing rewrite-clj users who have stumbled against this behavior would have special code to work around it.

If a user of rewrite-cljc, for some reason, felt a need to preserve the existing rewrite-clj behavior, we could support that with a dynamic variable. Perhaps rewrite-cljc/*elide-metadata* would default to [:line :column :end-line :end-column] but could be overridden to nil to offer a route to backwards compatibility. But on second thought, I think we'll just hardcode the eliding; the behaviour of including it, can be rationalize as a bug.

This change would:

  1. help mainstream users of rewrite-cljc under Clojure avoid an oddity in handling of quoted lists.
  2. simplify my sci tests; it would allow me to abandon my sci fork (which compensates from some metadata handling) and use sci master in a more straightforward manner.

Alternative Solutions
None, at present.

Action
I will experiment with above idea, and if fruitful, will effect the change.

@lread lread added this to Fixed in V1 branch in rewrite-clj Jan 22, 2021
@lread lread closed this as completed in d22b8a7 Mar 10, 2021
rewrite-clj automation moved this from Fixed in v1 branch to Done Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant