<< Back to previous view

[ASYNC-119] ClojureScript: combine cljs.core.async.macros and cljs.core.async Created: 15/Mar/15  Updated: 19/Aug/16

Status: Open
Project: core.async
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: J. S. Choi Assignee: Unassigned
Resolution: Unresolved Votes: 7
Labels: enhancement

Attachments: Text File ASYNC-119.patch    

 Description   

The macros in cljs.core.async.macros can now be moved into the cljs.core.async namespace, now that combined .cljs/.clj namespaces are possible in ClojureScript. This, along with ClojureScript 0.0-2755's recent improvements, would enable users to use `(require [cljs.core.async :refer [go go-loop ...])` without having to distinguish between functions and macros, and without having to use `require-macros` at all.



 Comments   
Comment by J. S. Choi [ 14/Oct/15 9:19 PM ]

ASYNC-142 (http://dev.clojure.org/jira/browse/ASYNC-142) proposes renaming the ClojureScript namespace from cljs.core.async to clojure.core.async, which would supersede this improvement.

Personally, I would love for ASYNC-142 to happen, though if it ends up being held back for a major change across all clojure.core projects, as Alex Miller suggested on its ticket, then this improvement may still be worth doing in the meantime.

Comment by Tim Gilbert [ 19/Aug/16 1:35 PM ]

There have been a few recent developments to ClojureScript that might make this a bit more feasible now.

Notably, the 1.9.216 ClojureScript will now import cljs.* namespaces which are referenced as clojure.* via CLJS-1692, and it will infer which referenced things from a namespace are macros versus functions via CLJS-1507.

One can currently import the functions in cljs.core.async using the same syntax as Clojure:

(ns my.app 
  (:require [clojure.core.async :refer [<! >!]]))

To get the macros, however, a separate (:require-macros) call is needed:

(ns my.app 
  (:require-macros [cljs.core.async.macros :refer [go go-loop]]))
  (:require [clojure.core.async :refer [<! >!]]))

If the macros were moved from cljs.core.async.macros into cljs.core.async, one could use the same syntax from either Clojure or ClojureScript:

(ns my.app 
  (:require [clojure.core.async :refer [<! >! go go-loop]]))

On the ClojureScript Slack channel David Nolen indicated that this would be a breaking change, and with questionable value relative to that. I think it might be worth talking about, though - in theory, at least, I could imagine an implementation that moves the macros into cljs.core.async and leaves aliases or shim versions around in the old cljs.core.async.macros namespace for backwards compatibility.

Comment by Juho Teperi [ 19/Aug/16 2:31 PM ]

Here is a patch which moves the macros but adds shim vars to the macros ns. The idea for shim vars has been take from Potemkin: https://github.com/ztellman/potemkin/blob/master/src/potemkin/namespaces.clj

There is one minor case where this will break user's code:

(:require-macros [cljs.core.async.macros :as a)
(:require [cljs.core.async :as a])

It has been possible to use same alias for macro and cljs namespace, but this won't work if macro namespace exists with the same name as cljs namespace. BUT I don't think this is a problem, because this has never been intended to be supported.

Most people probably use :require-macros with :refer, and this continues to work after this patch:

(:require-macros [cljs.core.async.macros :refer [go])
(:require [cljs.core.async :as a])

Tested with clojurescript 1.9.89 and 1.9.225.





[ASYNC-142] Rename ClojureScript namespace from cljs.core.async to clojure.core.async Created: 18/Aug/15  Updated: 19/Aug/16

Status: Open
Project: core.async
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Daniel Compton Assignee: Unassigned
Resolution: Unresolved Votes: 3
Labels: None


 Description   

I'm not sure what the original reasoning for using separate namespaces for the Clojure and ClojureScript versions of core.async were, but now with Reader Conditionals people are able to write cross platform code that targets both at the same time. For that reason, it would be nice to only need to require clojure.core.async so that the require didn't need to be split into two platform specific requires for the same library.

The biggest downside to this is that it would break backwards compatibility. However core.async is still in alpha, and updating code to reference the new namespace should be simple and able to be done quickly. It may be possible to leave a shim namespace in place for some time to allow people to migrate their code.

Thoughts?



 Comments   
Comment by Alex Miller [ 18/Aug/15 8:36 AM ]

I think we should do this, but it will likely be in tandem with a bigger set of changes (build, moving away from Clojure 1.6, etc).

Comment by Thomas Heller [ 03/Oct/15 5:48 AM ]

The biggest problem here are macros. The CLJS implementation (and cljs.core.async.macros) is very different from the CLJ one. Given that CLJS still requires :require-macros to use macros I doubt we can come up with a solution that does NOT require Reader Conditionals in their NS form.

CLJS can easily do away with macros requiring the extra :include-macros or :refer-macros (instead of just :refer) though. David Nolen rejected my initial implementation but was open to addressing the issue somewhere else [1]. I never went to pursue this via JIRA but it is probably something that should be solved prior to renaming things from cljs.core.async.

[1] http://dev.clojure.org/jira/browse/CLJS-948?focusedCommentId=37666&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-37666

Comment by Tim Gilbert [ 19/Aug/16 1:17 PM ]

cljs.* to clojure.* namespace aliasing was added in CLJS-1692 (ClojureScript 1.9.198), which fixes part of this issue; one can now use this form to import functions from core.async in ClojureScript:

(ns my.app 
  (:require [clojure.core.async :refer [<! >!]]))

Unfortunately, the core.async macros, notably (go), still live in a different namespace in the ClojureScript version of the library. ASYNC-119 proposes collapsing the two namespaces into one. I would think that this ticket itself could be closed now, however.





Generated at Thu Aug 25 17:09:04 CDT 2016 using JIRA 4.4#649-r158309.