-
Notifications
You must be signed in to change notification settings - Fork 3
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 unresolved recursive values as their defining expressions, instead of ??
#3
base: master
Are you sure you want to change the base?
Conversation
…s `??` so it's easier to develop recursive maps.
??
@aroemers I would update the README too and add some tests, but first, I would like to know if you see any problem with the feature itself or with the implementation approach. I have the gut feeling that there was some strong reason for just using |
Hi @onetom, Thank you for your PR and clear description. Know that I am pondering about your idea. Something that comes to mind is maybe printing it as |
We were thinking about using rmap in ClojureScript too and not sure what complications would reader tags impose. Apart from that, it makes unevaluated values stand out better, so that's undoubtedly helpful. I was also wondering, if it would be possible to have a simpler implementation of rmap, which doesn't utilize custom types, so it could run on Babashka out of the box too. 🤔 |
Me neither, I don't use ClojureScript all that much. I don't have plans to support it myself, and I don't think it'll work out of the box as it is now. That said, printing something as a reader tag should not hinder ClojureScript I guess?
It took more work than expected, but I managed to create the
It should certainly be possible, though I'm not sure whether the implementation would become simpler. On the other hand, printing recursive values nicely would become more difficult. Babashka does support defrecord, but overriding its printing is not as easy as adding I'm open for ideas :) |
@@ -64,7 +64,8 @@ | |||
not evaluated yet. The body can use the [[ref]] function while it is | |||
evaluated, or you can bind it locally for use at a later stage." | |||
[& body] | |||
`(RVal. (fn [ref#] | |||
`(RVal. ^{:ref/sexp '~@body} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unquote-splice would make the macro fail if the body contains multiple expressions like (rval (println "lazy!") "hi")
.
Thank you for the Alternatively, The best I could come up with is Then the reader tags could be {:a 1 :b #rmap/rval (inc #rmap/$ :a)} or when using {:a 1 :b (rval (inc ($ :a))} but using {:a 1 :b (rmap/rval (inc (rmap/$ :a)))} I will experiment with this |
I just got back to this feature finally. I see there are still certain cases, when @(def my-data-map {:foo 1 :bar #rmap/ref :foo})
;=> {:foo 1, :bar #rmap/ref :foo}
@(def my-rmap (rmap my-data-map))
;=> {:foo #rmap/rval ??, :bar #rmap/rval ??} but I saw in your previous commit how this is actually an improvement over the previous {:foo #rmap/rvalv__1727__auto__, :bar #rmap/rvalv__1727__auto__} I think the |
Having the following definition for (defn ^:no-doc rmap* [m]
(reduce-kv (fn [a k ??] (assoc a k (RVal. (.f (rval ??)) ??))) m m)) However, I found that this function is not covered by the test suite. |
Problem
While developing rmaps in a REPL session, they are printed with all the values appearing as
??
, which makes debugging hard.The following 3 expressions:
yield this output:
Solution
Store the rval-computing expressions (as metadata on their underlying function) and print those expressions, instead of
??
.The same 3 expressions as above, will be printed as:
While the printed values happen to be homoiconic, it was not a design goal.