No :exclude option for :require in Clojurescript?

631 views
Skip to first unread message

mars0i

unread,
Sep 25, 2016, 11:41:33 PM9/25/16
to ClojureScript
This compiles in Clojure 1.9.0-alpha12 but not in Clojurescript 1.9.229:

(ns free.matrix-arithmetic
(:require [clojure.core.matrix :as mx :exclude [e*]]))

The error in Clojurescript is:

clojure.lang.ExceptionInfo: Only :as, :refer and :rename options supported in :require / :require-macros; offending spec: [clojure.core.matrix :as mx :exclude [e*]] ...

The code compiels in Clojurescript if I remove ":exclude [e*]".

Is :exclude going away as an option to require and :require, and Clojurescript is ahead of Clojure? Is this a bug?

Phill Wolf

unread,
Sep 26, 2016, 5:28:09 AM9/26/16
to ClojureScript
There is no :exclude in the Clojure API documentation for require. The errant line of code might be a mix-up between require and use.

Alex Miller

unread,
Sep 26, 2016, 8:39:47 AM9/26/16
to ClojureScript

:exclude is not a valid option here (it's not having any effect). (doc require) mentions only :as and :refer as valid options in the libspec. :exclude is an option for :refer and :refer-clojure, not for :require.

It's maybe interesting that the spec for ns does not report this problem here in :clojure.core.specs/prefix-list because of the use of keys*, which takes an open map view of options. I'll have to check with Rich if this is something we want to lock down more.

mars0i

unread,
Sep 26, 2016, 10:54:53 AM9/26/16
to ClojureScript
> :exclude is not a valid option here (it's not having any effect). (doc require) mentions only :as and :refer as valid options in the libspec. :exclude is an option for :refer and :refer-clojure, not for :require.
>
> It's maybe interesting that the spec for ns does not report this problem here in :clojure.core.specs/prefix-list because of the use of keys*, which takes an open map view of options. I'll have to check with Rich if this is something we want to lock down more.

I see. Thanks. If I wanted to pull in everything but e*, for example, I could use :exclude, but there's no reason to exclude anything if I'm only using specific, namespace-qualified functions from clojure.core.matrix.

I had noticed that the docstring for require didn't mention exclude, but with some of the more complex macros and functions like require, there are sometimes minor points missing from docstrings. (That's not a complaint.)

I don't need :exclude at present, but I still can't figure out how I could pull in all functions but one from a namespace. For example, the Clojurescript compiler doesn't like this:

(ns free.matrix-arithmetic
(:require [clojure.core.matrix :as mx :refer :all :exclude [e*]]))

The spec failure report:

clojure.lang.ExceptionInfo: Only :as, :refer and :rename options supported in :require / :require-macros; offending spec: [clojure.core.matrix :refer :all :exclude [e*]] ...

Similarly, this

(ns free.matrix-arithmetic
(:use [clojure.core.matrix :exclude [e*]]))

results in this

clojure.lang.ExceptionInfo: Only [lib.ns :only (names)] and optionally `:rename {from to}` specs supported in :use / :use-macros; offending spec: [clojure.core.matrix :exclude [e*]] ...

Alex Miller

unread,
Sep 26, 2016, 11:13:58 AM9/26/16
to clojur...@googlegroups.com
I think this would do what you want:

(ns free.matrix-arithmetic
  (:require [clojure.core.matrix :as mx])
  (:refer clojure.core.matrix :exclude [e*]))



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/y1vVdKp5EYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescript+unsubscribe@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

mars0i

unread,
Sep 26, 2016, 2:24:27 PM9/26/16
to ClojureScript
On Monday, September 26, 2016 at 10:13:58 AM UTC-5, Alex Miller wrote:
> I think this would do what you want:
>
> (ns free.matrix-arithmetic
>   (:require [clojure.core.matrix :as mx])
>   (:refer clojure.core.matrix :exclude [e*]))

Thanks very much. I didn't understand that the :refer expression is separate from the :require expression in an ns statement.

This still produces an error in Clojurescript 1.9.229. It seems to say that :refer is not allowed in ns:

clojure.lang.ExceptionInfo: Only :refer-clojure, :require, :require-macros, :use, :use-macros, and :import libspecs supported at line 1 ... :tag :cljs/analysis-error


I just noticed some things about ns docstrings:

The docstrings for ns in Clojure 1.8.0 and 1.9.0-alpha12 don't mention :refer at all.

The docstring in Clojurescript 1.9.299 says that ":require supports :as, :refer, and :rename", which I would read as implying that :refer belongs somewhere inside a :require expression. However, :exclude is only mentioned in relation to :refer-clojure.


At this point, :exclude is just something to be curious about for me, since I rarely pull all or almost all of a namespace into another one. Maybe I'll leave it alone now that I've flagged some questions? I don't understand enough to submit relevant tickets.

Alex Miller

unread,
Sep 26, 2016, 2:57:20 PM9/26/16
to ClojureScript
On Monday, September 26, 2016 at 1:24:27 PM UTC-5, mars0i wrote:
> On Monday, September 26, 2016 at 10:13:58 AM UTC-5, Alex Miller wrote:
> > I think this would do what you want:
> >
> > (ns free.matrix-arithmetic
> >   (:require [clojure.core.matrix :as mx])
> >   (:refer clojure.core.matrix :exclude [e*]))
>
> Thanks very much. I didn't understand that the :refer expression is separate from the :require expression in an ns statement.
>
> This still produces an error in Clojurescript 1.9.229. It seems to say that :refer is not allowed in ns:
>
> clojure.lang.ExceptionInfo: Only :refer-clojure, :require, :require-macros, :use, :use-macros, and :import libspecs supported at line 1 ... :tag :cljs/analysis-error

This may be one area where Clojure and ClojureScript differ (I don't follow ClojureScript with close enough attention to know). It's also possible that the spec is wrong and it should *not* include refer at all. In that case, I run the risk that my suggestion above that will be deemed invalid in a later alpha. :) You can also do the refer outside the ns as another (perhaps preferred) alternative:

(refer 'clojure.core.matrix :exclude '[e*])

> I just noticed some things about ns docstrings:
>
> The docstrings for ns in Clojure 1.8.0 and 1.9.0-alpha12 don't mention :refer at all.

Yeah, there are a number of places where the docstrings are imprecise. We are trying to bring more precision by defining specs here. The specs should help achieve greater alignment over time.

> The docstring in Clojurescript 1.9.299 says that ":require supports :as, :refer, and :rename", which I would read as implying that :refer belongs somewhere inside a :require expression. However, :exclude is only mentioned in relation to :refer-clojure.

:require has support for some (but not all) refer functionality. :refer-clojure is just refer applied specifically to clojure.core so they share the same options pretty much.

Does this all make perfect sense? Perhaps not. Unfortunately ns and friends were added early in Clojure with perhaps less scrutiny than was prudent given their importance and they have evolved in non-optimal ways.

> At this point, :exclude is just something to be curious about for me, since I rarely pull all or almost all of a namespace into another one. Maybe I'll leave it alone now that I've flagged some questions? I don't understand enough to submit relevant tickets.

I don't know that anything needs to be followed. If anything, I think a CLJ ticket about whether :refer should be supported in the ns spec is my biggest question.


António Monteiro

unread,
Sep 26, 2016, 6:38:04 PM9/26/16
to ClojureScript

FWIW, beware that locking this down further would have to account for ClojureScript's `:refer-macros` and `:include-macros`, etc.

Alex Miller

unread,
Sep 26, 2016, 7:30:57 PM9/26/16
to clojur...@googlegroups.com
On Mon, Sep 26, 2016 at 5:38 PM, António Monteiro <anmon...@gmail.com> wrote:


FWIW, beware that locking this down further would have to account for ClojureScript's `:refer-macros` and `:include-macros`, etc.

CLJS will already need a different spec than CLJ for ns to account for this so we're already planning on that.

Reply all
Reply to author
Forward
0 new messages