clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
borkdude 2020-09-09T19:40:43.106100Z

Pushed the experiment to a repo: https://github.com/clj-kondo/inspector Contributions welcome.

borkdude 2020-09-09T19:49:37.107200Z

Hmm, I realize that this is just valid Clojure syntax:

(defn foo [^:int x ^:keyword y ^:string z]
  [x y z])

(prn (foo 1 2 3))
Could be a way to integrate clojure spec with existing defns without the need for writing another macro.

borkdude 2020-09-09T19:49:55.107500Z

Non-namespaced keyword: refers to a predicate, namespaced keyword: refers to a spec

borkdude 2020-09-09T19:51:00.107900Z

e.g.:

(s/def ::s string?)

(defn foo [^:int x ^:keyword y ^:ss z]
  [x y z])

alexmiller 2020-09-09T19:52:43.108200Z

we're not going to do that, but there are some other ideas percolating

🐟 1
borkdude 2020-09-09T19:55:43.108500Z

Unambiguous:

user=> (alias 'c 'clojure.core)
nil
user=> ::c/int?
:clojure.core/int?
user=> (defn foo [^::c/int? x])

borkdude 2020-09-09T19:56:30.109400Z

Bit ugly, but one of those things that could have been deemed: yeah, Rich intended it like this all along, it was all from a design originating back to 2002 ;)

alexmiller 2020-09-09T19:58:14.109700Z

except it's the opposite of what Rich intends :)

borkdude 2020-09-09T19:58:39.110Z

tell me more

alexmiller 2020-09-09T19:59:45.110900Z

this just plays to the familiarity from static typing langs, which is just not what Rich is trying to do with spec

borkdude 2020-09-09T20:01:35.111700Z

This would not be limited to simple annotations. You could do:

user=> (s/def ::foo (s/keys :req-un [::x]))
:user/foo
user=> (defn f [^::foo m])
so I don't get the static typing remark.

alexmiller 2020-09-09T20:04:57.112200Z

it looks like static typed function signatures, but it's not

borkdude 2020-09-09T20:05:07.112400Z

so?

alexmiller 2020-09-09T20:05:24.112800Z

so making things that are different look the same causes confusion

alexmiller 2020-09-09T20:07:02.113800Z

there are other considerations as well - compilation, evaluation, reuse across arities, combination with other features that don't exist yet, etc

alexmiller 2020-09-09T20:07:41.114400Z

Rich is looking at all that and considering a wide variety of options including the one above

👍 1
borkdude 2020-09-09T20:07:59.114700Z

I bet

alexmiller 2020-09-09T20:08:15.115100Z

I just think this one is probably unlikely based on what I've heard