Fork me on GitHub

is there an example of clojure.spec-ing either SVG or HTML so if my 'hiccup data' passes the spec, it's valid HTML/SVG ?


in standard usage of spec, when ::foo shows up in different maps (of the same namespace), is it expected that the value associated with ::foo will always be of the same 'shape' ?


in spec the mapping of a qualified keyword to a spec (shape) is global by design, so yes.


though you can make the spec match a set of pretty much arbitrary shapes if you’re set on doing that.


qqq: Well the value of ::foo must match whatever the spec behind ::foo says. You can use spec/or or similar for disjunction.


qqq: as for a hiccup "spec", I used in the past. This also has the benefit of conforming to a nice tree that can be converted to html by a simple tree-walk. Note that :tag is just keyword?, you can extend htis and :attrs with better specs describing the set of allowed tags / attributes.


Question about type hinting: I have code like: (def ms-per-second 1000) (def ms-per-minute (* ms-per-second 60)) - I get a boxed math warning w/ that second def unless I use (def ms-per-minute (* ^long ms-per-second 60)). I'd like to type hint ms-per-second once where it's defined to avoid needing to type hint it everywhere it's used. Is that possible?


however if you want to avoid boxing, you should probably use ^:const too


Could you please show me what that syntax looks like? I haven't been able to get any placement of the ^long hint to work. I get this error: java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$long@5aadb195


in pseudo syntax, what's happening is w/o type hint: Numbers.multiply (Long(60), (Long)ms-per-second.get()), w/ type hint: Numbers.multiply((long) 60, ms-per-second.get().longValue()), w/ const Numbers.multiply((long) 60, (long) 1000))


just (def ^{:const true :tag 'long} ms-per-second 1000)


or (def ^:const ^long ms-per-second 1000)


the long tag is actually useless with const as the compiler will be able to infer it after inlining


Thank you very much


@abdullahibra that use case is very easy to handle with specter: (transform [ALL (srange 0 2)] clojure.string/reverse ["hello" "world"])


a great example of using composition to avoid having to reinvent the wheel (in this case, string reversal)


can you type hint the return of a protocol function signature?


or do you have to do it at the call site?


(defprotocol P (f ^MyType [..]))


don’t know why I didn’t just try it lol


Is there a proper channel for asking 1.9 questions? #clojure-spec ?


if they're about spec ask there, otherwise here is fine


is there anything special about `unq in

(s/def :unq/person
  (s/keys :req-un [::first-name ::last-name ::email]
          :opt-un [::phone]))

or is this literally the :person keyword in the unq namespace ?


:unq is the namespace part of the :unq/person keyword


there’s nothing really special about it, it could be anything


@U3JURM9B6 the single : syntax doesn’t presuppose any loading, so there’s no guarantee that unq maps to a namespace at all. :: will implicitly be a real namespace, as it will either be the current namespace or ::alias/foo where alias will have to have been require :as’d.


@U06HHF230 @U3DAE8HMG: makes sense; thanks!


hey all. I need to set an Object’s field but I don’t know it’s name until runtime.


I’d like to do do: (set! (.-field object) value) but I have .-field as a String.

Garrett Hopper17:11:47

Anyone know of a way to use ring or bidi to create a url with certain query params from a map? Doing string concatenation feels wrong in this case. I'm trying to general an oauth redirect link.


Thanks @hiredman I was beginning to suspect I’d need to fall back on Java’s reflection.


definitely with bidi you should be using one of its built in functions for doing that


Is there a recommended way to use protobuf with clojure? The first few projects that come up after a google search don't seem to be actively maintained. I'm specifically looking for something that plays nice with repl dev


(s/def :event/type keyword?) 
(s/def :event/timestamp int?) 
(s/def :search/url string?) 
(s/def :error/message string?) 
(s/def :error/code int?)

(defmulti event-type :event/type)

(defmethod event-type :event/search [_]
  (s/keys :req [:event/type :event/timestamp :search/url])) 

(defmethod event-type :event/error [_]
  (s/keys :req [:event/type :event/timestamp :error/message :error/code]))

(s/def :event/event (s/multi-spec event-type :event/type))

(s/explain :event/event
          {:event/type :event/search
           :event/timestamp 123456789
           :search/url ""})
can someone please explain to me why this is failing? I don't understand the error of: val: {:event/type :event/search, :event/timestamp 123456789, :search/url ""} fails spec: :event/event at: [nil] predicate: event-type, no method


you should join the #clojure-spec channel too


ah, it works now: the above code works fine; problem was, I initially defined the defmulti wrong, and then upon correction, it was not being redefined until I called a remove-ns


So in working on an application which interacts with PSQL, I’ve setup some standard tooling which pulls dates out of the records and transforms them from sql times to jodatimes (because clj-time has this functionality). However, in working with 1.9, the inst? operator expects a I’m curious if there’s been any public conversation around what timestamps clj should be using going forward, especially now considering there’s java.time in jdk 8, etc.


@amann inst? works just fine for java.time.Instant


Good point. My above question was from a standpoint of what should I expect to be using in 6 months, etc. Thanks for pointing this out!


@amann I think at this point I would switch to Java Time. I'm one of the maintainers of clj-time and we've been wrestling for a long time with the question of whether to migrate/produce a new version of clj-time on top of Java Time. The feeling is that we can't realistically do it in a compatible way and therefore we'd need a new artifact name (rather than change the API and/or semantics and violate the spirit of Rich's Spec-ulation talk) -- so it would be a "new" library altogether (similar to clj-time). But none of us have the time(!) or inclination for that, so I'm switching to which is based on Java Time and that's what I'm recommending folks use.


I've introduced at work and we're slowly migrating off our current combination of date-clj (for java.util.Date stuff) and clj-time (for Joda Time stuff).


This is great information. Thanks Sean. The debates we’ve had at work have been mostly the same, but having some indication from the maintainer of clj-time itself definitely helps.


clj-time will continue to be maintained, but it's much less useful now we have Java Time. I've been very happy with so far in production code.


i'm trying to use spyscope from Added the dependency to my project.clj but when I try and add [require [spyscope.core as spy] in my namespace, repl refuses to start. The error is:

Exception in thread "main" clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec:
In: [2] val: ((require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt])) fails spec: :clojure.core.specs.alpha/ns-form at: [:args] predicate: (cat :attr-map (? map?) :clauses :clojure.core.specs.alpha/ns-clauses),  Extra input
 #:clojure.spec.alpha{:problems [{:path [:args], :reason "Extra input", :pred (clojure.spec.alpha/cat :attr-map (clojure.spec.alpha/? clojure.core/map?) :clauses :clojure.core.specs.alpha/ns-clauses), :val ((require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt])), :via [:clojure.core.specs.alpha/ns-form], :in [2]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x3c7c886c "clojure.spec.alpha$regex_spec_impl$reify__2436@3c7c886c"], :value (spyscope.core "This co" (require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt])), :args (spyscope.core "This co" (require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt]))}, compiling:(spyscope/core.clj:1:1)
any clues? (oh, and I'm using clojure 1.9.0-RC1)


@clojurian Which version of spyscope did you use?


0.1.6 is the latest.


Looks like 0.1.6 includes the fix for the issue you saw above -- I see commits fixing the ns forms.


Although it looks like you may run into this until the maintainer releases 0.1.7.


(that starts out as the bug you encountered @clojurian but notes there's a 0.1.6 release but that also has a blocking bug and the library needs a 0.1.7 release made, since the fix is already merged)


Hi; I’d like to experiment with program obfuscation and one part I’d like to do via term rewriting — does anyone have a favorite term rewriting library? It seems expresso and stratege and termito are the common ones; expresso seems to be focused on symbolic mathematical expressions, but I don’t think that really matters