spec2 s/def improvement

63 views
Skip to first unread message

Ambrose Bonnaire-Sergeant

unread,
Feb 25, 2020, 10:51:58 PM2/25/20
to Clojure Dev
Hi,

Hopefully this is useful feedback, but in spec2 I noticed that s/def's can't use :refer'd macros.
This is because clojure.alpha.spec/ns-qualify does not pick up on :refer'd vars.

eg.,
(ns one)
(defmacro my-spec ...)

(ns two
  (:require [clojure.alpha.spec :as s]
            [one :refer [my-spec]]))

; this blows up
(s/def ::foo (my-spec ...))
; (Approximate error msg)
; Unable to def ::foo, unknown spec op: two/my-spec

; this works fine
(s/register ::foo (my-spec ...))

Happy to provide more info if needed.

Thanks,
Ambrose

Alex Miller

unread,
Feb 25, 2020, 10:57:18 PM2/25/20
to Clojure Dev
What does my-spec look like?

My first answer would be that this isn't intended to be supported, as s/def takes a narrower range of symbolic specs in spec 2, but I'd like to have a more concrete example.

s/register (not a macro) takes a resolved spec object (not a symbolic spec), so might be the better choice here.

Ambrose Bonnaire-Sergeant

unread,
Feb 26, 2020, 6:57:59 PM2/26/20
to Clojure Dev
Here's a concrete example using a spec already defined in spec2.
Hopefully it illustrates the problem (which seems like an unintentional bug to me).

(ns spec-def.core
  (:refer-clojure :exclude [or])
  (:require [clojure.alpha.spec :as s :refer [or]]))

(s/def ::foo (or)) ;Syntax error macroexpanding s/def at (core.clj:5:1).
                   ;Unable to def :spec-def.core/foo, unknown spec op: spec-def.core/or

Alex Miller

unread,
Feb 26, 2020, 9:09:16 PM2/26/20
to cloju...@googlegroups.com
Yep, that seems wrong. 

Fixed in master, thanks...

--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure-dev/22bf3407-8a66-4ffd-8832-32106d8a086e%40googlegroups.com.

Ambrose Bonnaire-Sergeant

unread,
Feb 26, 2020, 10:50:07 PM2/26/20
to Clojure Dev
Wonderful! Confirmed fixed. Thanks for the awesome library.

Ambrose
To unsubscribe from this group and stop receiving emails from it, send an email to cloju...@googlegroups.com.

Ambrose Bonnaire-Sergeant

unread,
Feb 27, 2020, 11:14:09 AM2/27/20
to cloju...@googlegroups.com
Sure, here's a concrete example using a spec already defined in spec2.

(ns spec-def.core
  (:refer-clojure :exclude [or])
  (:require [clojure.alpha.spec :as s :refer [or]]))

(s/def ::foo (or)) ;Syntax error macroexpanding s/def at (core.clj:5:1).
                   ;Unable to def :spec-def.core/foo, unknown spec op: spec-def.core/or




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages