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 combining macros/functions in one namespace #134

Closed
Engelberg opened this issue Jul 8, 2016 · 7 comments
Closed

Consider combining macros/functions in one namespace #134

Engelberg opened this issue Jul 8, 2016 · 7 comments

Comments

@Engelberg
Copy link

The README demonstrates using specter by "using" both the macros and specter namespaces. But some of the names are common enough that I would prefer to "require" them with an alias. The problem: because the README only demonstrates usage with no namespace qualifications, it is not obvious how to remember which parts of the API are functions and which are macros, and therefore it can be hard to recall which namespace to find which thing in. To some extent, macros vs functions are an implementation detail, and I as a user don't necessarily know which way a given thing is implemented.

Consider combining macros/functions into a unified API of all the core public API functions (it's fine if things like transients remain separate, since that is a conceptual classification that is easy to remember, not an implementation-based classification).

Potemkin is a valuable tool for pulling things from separate implementation namespaces into one API namespace for public consumption.

@nathanmarz
Copy link
Collaborator

I agree, and this is how it used to be. The split was done for ClojureScript compatibility.

@Engelberg
Copy link
Author

Engelberg commented Jul 8, 2016

I have found potemkin's import-vars to be a great tool for dealing with this. import-vars copies over the docstring and other pertinent info about the var from the implementation namespace to the API namespace -- works seamlessly on both functions and macros.

So, potentially you could keep the separate implementation namespaces for Clojurescript users, but Clojure users could access the vars through a com.rpl.specter.core namespace.

Main downside of using potemkin is that it contains a lot of other stuff irrelevant to this particular use and the other stuff causes it to be somewhat fragile -- tends to break when new versions of Clojure come out until potemkin is updated. I wish Clojure had a built-in solution for something like import-vars.

@nathanmarz
Copy link
Collaborator

Apparently ClojureScript allows a macros namespace to be the same name as a ClojureScript namespace (not sure if this was added recently or not). That means Specter's namespaces can be merged.

@Engelberg
Copy link
Author

Engelberg commented Aug 22, 2016 via email

@nathanmarz
Copy link
Collaborator

nathanmarz commented Sep 4, 2016

Tried doing this today but ran into a major problem. When I put the macros namespace in specter.clj and keep the functions in specter.cljc, only the specter.clj file is loaded when doing a use at a Clojure repl:

user=> (use 'com.rpl.specter)
nil
user=> ALL

CompilerException java.lang.RuntimeException: Unable to resolve symbol: ALL in this context, compiling:(/private/var/folders/w6/4l9gm76n00bckj3210cv1rdw0000gn/T/form-init27325069843801310.clj:1:4652) 
user=> select

CompilerException java.lang.RuntimeException: Can't take value of a macro: #'com.rpl.specter/select, compiling:(/private/var/folders/w6/4l9gm76n00bckj3210cv1rdw0000gn/T/form-init27325069843801310.clj:1:4652)

Doing (load-file "src/clj/com/rpl/specter.cljc") gets it working, but that's not a satisfactory solution.

@aengelberg
Copy link
Contributor

Yeah, I don't think having both a clj and a cljc file for a given namespace is a supported use case. Couldn't you put the macros into specter.cljc but using the #?(:clj) reader conditional?

@nathanmarz
Copy link
Collaborator

Great idea, that worked. This is now implemented for 0.13.0.

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

3 participants