-
Notifications
You must be signed in to change notification settings - Fork 108
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 namespaced keys, part II #126
Comments
But I guess this would break the usage of keyworded keys identifying submaps? :( ; {:a {::x 1, ::y 2}}
[:a ::x ::y]
; {::a {::x 1, ::y 2}} or {::a 0, ::x 1, ::y 2}?
[::a ::x ::y] |
Interesting. Yeah, it would break the sub-maps. It's also weird to me I don't see an easy way to make this work without breaking something, or On Fri, Jun 10, 2016 at 12:55 PM, Tommi Reiman [email protected]
|
Thinking aloud: what if the default would be like it's today: (-> [:a ^:keys [::x ::y ::z]] second meta)
; => {:keys true} for top-level, it's bit hairy at the meta-data falls out of the arguments vector: (defnk just-keys ^:keys [::x ::y ::z] ...) Also, somehow related: http://dev.clojure.org/jira/browse/CLJ-1910 |
Eh, I'm wary of the idea of behavior changing based on metadata on the arg What about using quote to indicate alias resolution, e.g. (defnk just-keys ['x 'y 'alias/z] ...]) It currently errors so wouldn't break anything, and is at least somewhat Thoughts? On Fri, Jun 10, 2016 at 1:56 PM, Tommi Reiman [email protected]
|
Thanks for the thoughts. The quoted-syntax would work, but IMO it's bit (too) off from the current clojure syntax. Tried to figure out other ways to do this nicely, but all would require some special marker to define the "just keys" case. For (my) common case, this would not be a problem as sub-map keys are currently 100% not namespaced. But, spec might change this too. Alex pointed me that the destructuring syntax is about to be modified (http://dev.clojure.org/jira/browse/CLJ-1919) in clojure, in contrast to that, few new suggestions: Clojure;; non-namespaced
(fn [{{{:keys [name sex age]} :body-params} :request}]
(println "created user:" name sex age))
;; namespaced
(fn [{{{:keys [user/name user/sex user/age]} :body-params} :request}]
(println "created user:" name sex age))
;; namespace-aliased
(fn [{{{:keys [::u/name ::u/sex ::u/age]} :body-params} :request}]
(println "created user:" name sex age))
;; namespace-aliased (with CLJ-1919)
(fn [{{{::u/keys [name sex age]} :body-params} :request}]
(println "created user:" name sex age)) Plumbing;; non-namespaced (works already)
(fnk [[:request [:body-params name sex age]]]
(println "created user:" name sex age))
;; namespaced (works already)
(fnk [[:request [:body-params user/name user/sex user/age]]]
(println "created user:" name sex age))
;; namespaced (idea, CLJ-1919 -style)
(fnk [[:request [:body-params ^:user/keys [name sex age]]]]
(println "created user:" name sex age))
;; namespace-aliased (idea, CLJ-1919 -style)
(fnk [[:request [:body-params ^::u/keys [name sex age]]]]
(println "created user:" name sex age)) Is this too confusing to have the tagged sub-vectors? also, has about the same number of characters as the clojure version, just in the reverse order - which is good for readability, but more complex than the current plumbing syntax.
Not 100% sure this is a good idea :) At least, the clojure core changes should to be finalised before doing anything. I'll keep this open, ok? |
Thanks for the detailed writeup! I'm fine with using metadata to indicate a prefix, just wasn't excited The name There is also the question of how this plays with nested keys. Does [a ^:foo/keys [:b [:c d]] bind {:a 1 :foo/b {:foo/c {:foo/d 2}}? Is On Wed, Jun 15, 2016 at 2:07 PM, Tommi Reiman [email protected]
|
Another issue with namespaced keys that I've found is that you can't have bindings for two keys with the same name but different namespaces, e.g.:
This will fail with "Binding is not valid" error. |
I'd love to be able to use namespace aliases like this. Implementing spec in my project with namespaced keywords looks great everywhere except in my graph fnks, which have become horribly verbose. |
The issue mentioned by @danielcompton is still a thorn in my side. It's really the one major problem that's preventing me from using graph. |
Hi,
Would like to have better support for namspaced keys in fnk-destructuring. Current status:
which is great, but would like to support using namespaced keys for clarity as Clojure core support this:
.. so, would like this to work:
This would open open up the interoperability to
clojure.spec
as one could mix and match spec & schema annotations.With current plumbing schema extraction helpers and a lookup to the clojure.spec registry, it one can post-resolve (on the client code) the types for namespaced keys. With a separate mapping of schema predicate to spec, one could also generate either typed schemas using specs or (maybe) specs using the schemas.
The text was updated successfully, but these errors were encountered: