ClojureScript

support :include-macros true modifier in :require

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.

The following should be supported:

(ns foo.bar
  (:require [baz.woz :as woz :include-macros true))
(ns foo.bar
  (:require [baz.woz :as woz :refer [one] :refer-macros [two]))

I think the following is probably a bridge too far:

(ns foo.bar
  (:use [baz.woz :only [one] :include-macros [two]))

Activity

David Nolen made changes -
Field Original Value New Value
Assignee David Nolen [ dnolen ]
David Nolen made changes -
Status Open [ 1 ] In Progress [ 3 ]
Hide
Jozef Wagner added a comment -

Same goal as CLJS-563

Show
Jozef Wagner added a comment - Same goal as CLJS-563
Hide
David Nolen added a comment -

Thanks I've closed CLJS-563. The required explicit modifier here avoids unpleasant surprises.

Show
David Nolen added a comment - Thanks I've closed CLJS-563. The required explicit modifier here avoids unpleasant surprises.
Hide
Jozef Wagner added a comment -

What will be the semantics if only the .clj file is present on classpath?

Show
Jozef Wagner added a comment - What will be the semantics if only the .clj file is present on classpath?
Hide
David Nolen added a comment -

An error.

Show
David Nolen added a comment - An error.
David Nolen made changes -
Description This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without need both a :require-macros and :require. This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.
Hide
Thomas Heller added a comment -

I assume you plan something like this (if not ignore me):

(ns wants-to-use-macros
(:require [has-macros :as m :include-macros true])

Could we instead do something like

(ns has-macros
(include-macros))

or

(ns ^:include-macros has-macros)

Seems to me it would be more helpful to write the include-macros once instead of every time the ns is used?

Show
Thomas Heller added a comment - I assume you plan something like this (if not ignore me): (ns wants-to-use-macros (:require [has-macros :as m :include-macros true]) Could we instead do something like (ns has-macros (include-macros)) or (ns ^:include-macros has-macros) Seems to me it would be more helpful to write the include-macros once instead of every time the ns is used?
Hide
David Nolen added a comment -

Further complicating ns form parsing via metadata and custom forms is not on the table. I'm not particularly interested in convenience beyond removing two requires for two files that are logically related.

Show
David Nolen added a comment - Further complicating ns form parsing via metadata and custom forms is not on the table. I'm not particularly interested in convenience beyond removing two requires for two files that are logically related.
David Nolen made changes -
Description This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require. This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.

The following should be supported:

{code}
(ns foo.bar
  (:require [baz.woz :as woz :include-macros true))
{code}

{code}
(ns foo.bar
  (:require [baz.woz :as wiz :refer [one] :refer-macros [two]))
{code}

{code}
(ns foo.bar
  (:use [baz.woz :only [one] :include-macros [two]))
{code}
David Nolen made changes -
Description This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.

The following should be supported:

{code}
(ns foo.bar
  (:require [baz.woz :as woz :include-macros true))
{code}

{code}
(ns foo.bar
  (:require [baz.woz :as wiz :refer [one] :refer-macros [two]))
{code}

{code}
(ns foo.bar
  (:use [baz.woz :only [one] :include-macros [two]))
{code}
This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.

The following should be supported:

{code}
(ns foo.bar
  (:require [baz.woz :as woz :include-macros true))
{code}

{code}
(ns foo.bar
  (:require [baz.woz :as woz :refer [one] :refer-macros [two]))
{code}

{code}
(ns foo.bar
  (:use [baz.woz :only [one] :include-macros [two]))
{code}
David Nolen made changes -
Description This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.

The following should be supported:

{code}
(ns foo.bar
  (:require [baz.woz :as woz :include-macros true))
{code}

{code}
(ns foo.bar
  (:require [baz.woz :as woz :refer [one] :refer-macros [two]))
{code}

{code}
(ns foo.bar
  (:use [baz.woz :only [one] :include-macros [two]))
{code}
This modifier will additionally trigger a load of a Clojure file containing macros that matches the namespace. This would allow libraries to adopt cljs.core's inlining macro style without needing both a :require-macros and :require.

The following should be supported:

{code}
(ns foo.bar
  (:require [baz.woz :as woz :include-macros true))
{code}

{code}
(ns foo.bar
  (:require [baz.woz :as woz :refer [one] :refer-macros [two]))
{code}

I think the following is probably a bridge too far:

{code}
(ns foo.bar
  (:use [baz.woz :only [one] :include-macros [two]))
{code}
Hide
Thomas Heller added a comment -

Sorry to be blunt but I don't see where its more complicated to parse one extra form in the ns vs. parsing a far more complicated argument list in (:require) as you put in your example. Also trading one inconvenience (:require-macros) for another (:refer-macros, :include-macros) is only a small improvement.

IMHO its totally inconvenient that I a) have to remember which namespaces provide macros b) which defs were actually macros (assuming :refer). Assuming someone writes a library which provides some macros, shouldn't the library author worry about including the correct macros and let me just use it, just as in Clojure?

But I assume my proposal is more complex since you can't analyze a namespace on its own anymore (since any referred var may be a macro), which is a totally valid argument not to do it.

Show
Thomas Heller added a comment - Sorry to be blunt but I don't see where its more complicated to parse one extra form in the ns vs. parsing a far more complicated argument list in (:require) as you put in your example. Also trading one inconvenience (:require-macros) for another (:refer-macros, :include-macros) is only a small improvement. IMHO its totally inconvenient that I a) have to remember which namespaces provide macros b) which defs were actually macros (assuming :refer). Assuming someone writes a library which provides some macros, shouldn't the library author worry about including the correct macros and let me just use it, just as in Clojure? But I assume my proposal is more complex since you can't analyze a namespace on its own anymore (since any referred var may be a macro), which is a totally valid argument not to do it.
Hide
David Nolen added a comment -

Yes your suggestion has other implications. What I'm suggesting will desugar into existing supported functionality.

Show
David Nolen added a comment - Yes your suggestion has other implications. What I'm suggesting will desugar into existing supported functionality.
David Nolen made changes -
Resolution Completed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: