Fork me on GitHub
#beginners
<
2018-04-22
>
dpsutton03:04:35

@dimitri can you ask here and post a bit more code?

demi03:04:59

@dpsutton thanks! well, I just trying out exercises in and running tests with lein test, it works but throws a weird error if I try to require clojure.string for some reason…

demi04:04:36

Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec:
In: [1] val: ((require (quote [clojure.string :as s]))) fails spec: :clojure.core.specs.alpha/ns-form at: [:args] predicate: (cat :docstring (? string?) :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 :docstring (clojure.spec.alpha/? clojure.core/string?) :attr-map (clojure.spec.alpha/? clojure.core/map?) :clauses :clojure.core.specs.alpha/ns-clauses), :val ((require (quote [clojure.string :as s]))), :via [:clojure.core.specs.alpha/ns-form], :in [1]}], :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x4f186450 "[email protected]"], :clojure.spec.alpha/value (testns (require (quote [clojure.string :as s]))), :clojure.spec.alpha/args (testns (require (quote [clojure.string :as s])))}
	at clojure.core$ex_info.invokeStatic(core.clj:4739)
	at clojure.core$ex_info.invoke(core.clj:4739)
	at clojure.spec.alpha$macroexpand_check.invokeStatic(alpha.clj:689)
	at clojure.spec.alpha$macroexpand_check.invoke(alpha.clj:681)
	at clojure.lang.AFn.applyToHelper(AFn.java:156)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at clojure.lang.Var.applyTo(Var.java:702)
	at clojure.lang.Compiler.checkSpecs(Compiler.java:6889)

seancorfield04:04:53

@dimitri In an ns form, it should be (:require [clojure.string :as s])

seancorfield04:04:11

Looks like you have (require '[clojure.string :as s]) instead?

demi04:04:11

oh, using :require worked! However, all the examples I saw used require with ns, why is that?

demi04:04:30

require also works in cursive for some reason

seancorfield04:04:15

@dimitri Where did you see examples showing (require '[...]) inside ns? That's never been officially legal (sure, it worked pre-1.9, but it was bad code).

demi04:04:45

Oh I mean without the quote in front…

demi04:04:24

I just added that out of desperation

seancorfield04:04:35

There's a function require and that needs a quote. But the ns form should be :require without the '.

demi04:04:22

Got it, thank you!

kari09:04:01

I'm done with my first ClojureScript demo. Thanks for all the help Clojurians! I mentioned the Clojurians Slack as a great place for asking Clojure/ClojureScript related help in my blog: https://medium.com/@kari.marttila/become-a-full-stack-developer-with-clojure-and-clojurescript-c58c93479294

Chris15:04:21

Is there an elegant way to build a java.util.Properties from a map? I know it could be done by writing a short function but I’m a bit surprised there isn’t a conversion function already available in the standard library.

donaldball15:04:33

(let [props (java.util.Properties.)] (.putAll props m) props)

donaldball15:04:23

Or more succinctly

(doto (java.util.Properties.) (.putAll m))

Chris15:04:40

Cool, thanks 🙂