-
-
Notifications
You must be signed in to change notification settings - Fork 253
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 for clojure.datafy #468
Comments
@cldwalker |
Added |
@cldwalker I think clojure.datafy has to be added as a built-in namespace (either in sci or bb) due to some differences of what can be datafied (e.g. a sci namespace vs a clojure.lang.Namespace). What would be some useful example of having this in bb? |
Hi @borkdude, I might have a use case. I was thinking of adding support for the babashka runtime to portal. So far I have a basic http-socket-server setup, but things started to fail when I pulled in clojure.datafy. Let me know if there is anything I can do to help. |
@djblue I think this has to be built into the Clojure interpreter itself: It's on my list of things to look at, but feel free to experiment with it. |
@borkdude Sorry for the delay. My use case is that have a knowledge graph that I'm able to navigate with REBL. I'd like to build a bb CLI that improves on REBL by being more extensible. I'm only navigating basic data structures e.g. maps, sets and vectors so I'm not particularly concerned if there's no support for namespaces or vars initially. Another use case I could see for datafy is being a a helpful documentation reference for any java class or clj data structure e.g.:
I updated the first comment with a branch that is able to require clojure.datafy but I'm unable to observe working functionality. I don't know when I'll dig into this more but thought it'd be helpful to share progress |
I added a branch So this works:
But somehow memory usage during compilation spikes and the binary gets quite bloated (95MB). I would like to see more details about why this happens, before continuing. It could be related to the implementations of datafy for clojure namespaces, etc. Maybe including a patched version of clojure.datafy in babashka makes sense. I think I saw the same issue while trying to include spec. |
This is pretty weird. Just including a reference to This is the patched namespace I was using: |
This could be explained by some other dep loading
|
Discovered that the dep loading Commit 82016da in branch datafy:
This yields a normal sized binary. More research needed. Maybe we can patch |
Turns out that |
Made a PR here: https://github.com/borkdude/babashka/pull/526/files Could you both please check if babashka with this addition is working for your requirements? |
$ ./bb "(require '[clojure.datafy :as d]) (d/datafy Exception)"
{:bases #{java.lang.Throwable}, :flags #{:public}, :members {java.lang.Exception [#clojure.reflect.Constructor{:name java.lang.Exception, :declaring-class java.lang.Exception, :parameter-types [java.lang.String java.lang.Throwable], :exception-types [], :flags #{:public}} #clojure.reflect.Constructor{:name java.lang.Exception, :declaring-class java.lang.Exception, :parameter-types [java.lang.String], :exception-types [], :flags #{:public}} #clojure.reflect.Constructor{:name java.lang.Exception, :declaring-class java.lang.Exception, :parameter-types [java.lang.Throwable], :exception-types [], :flags #{:public}} #clojure.reflect.Constructor{:name java.lang.Exception, :declaring-class java.lang.Exception, :parameter-types [], :exception-types [], :flags #{:public}}]}, :name java.lang.Exception} |
@cldwalker Your example seems to work (minus the fact that
|
Part 1 is merged: support for |
In the
There's still a number of TODOs:
|
@borkdude This is all exciting work! Thanks for getting part 1 in. This example seems to works for me now |
I confirmed with the datafiable branch I'm able to navigate my data structures as in clj! I wasn't able to in master due to failing to require |
Pushed final commits to the datafiable branch. |
@borkdude Looks good to me. I was able to nav the hacker news api in babashka 🎉 |
Latest datafiable branch works great with my knowledge graph! 🕺 |
Merged! |
Hi. Exciting that defprotocol support is out! I'm opening this issue to track support for clojure.datafy.
Soon after defprotocol support landed on master, I tried requiringclojure.datafy
and ran into missing java classes e.g.Unable to resolve classname: java.lang.Iterable [at clojure/core/protocols.clj, line 34, column 6]
. Here's what I tried to remedy missing java classes:EDIT:
I'm able to require clojure.datafy with this branch. This branch adds all the java classes that namespace required. However when I try to exercise datafy functionality via clojure.datafy/datafy or clojure.datafy/nav, I don't see the expected behavior. To reproduce what I'm seeing, run the built ./bb of the above branch against this file e.g.
bb -f explore_data_nav.clj
. Observe thatnav-to-link
starting with this invocation returns a number instead of an expected map.It's unclear to me if I'm adding java classes in the wrong places, if there's a sci issue with defprotocol or something else. The above failing example only navigates maps. Any thoughts?
Is your feature request related to a problem? Please describe.
Would like to use clojure.datafy for navigating clojure data and java classes because of its first class reach in the language
Describe the solution you'd like
Would like require clojure.datafy to work
Describe alternatives you've considered
There isn't another that has the same functionality and is built into the language
Additional context
n/a
The text was updated successfully, but these errors were encountered: