Fork me on GitHub

@nathantech2005 Sounds more like a version mismatch. Recent versions use the new, standalone nrepl, not the contrib version. And that's possibly down the version of the plugin in Spacemacs...


I haven't used Emacs for years but you could try asking in #spacemacs (or #emacs if you can't get an answer there).


Yeah, if that's in your profiles.clj and you try to jack in with a different version of CIDER you will get the error you saw.


I very much doubt Spacemacs changed your profiles.clj -- but as a general point, I recommend having as few things in that file as possible. It's the #1 cause of problems with Leiningen for beginners 😞


Do specs have to be re-evaluated every time one of their nested specs gets redefined?



(s/def ::foo (s/coll-of ::bar))
(s/def ::bar int?)

(s/conform ::foo [1.0]) ;; => :clojure.spec.alpha/invalid


After changing

(s/def ::bar float?)
(s/conform ::foo ...) will continue using the old definition of ::bar and report now-valid things as invalid


This tripped me up a few times before, and now I generally put all specs in a single do block during development to make sure they get refreshed, just confused why it behaves this way for certain specs and not others (eg. s/keys doesn't have this issue)


Is this "Idiomatic" Clojure code for handling polymorpism? Both "mock" and "prod" implements the Api protocol but I will want to run the mock version depending on some config later on.


@UBN9SNVB4 Yes this is definitely idiomatic. This style is more suited to component than mount though. Take a look here: it might be better suited to your use case. IMO, it is much easier to mock resources/functionality in component than in mount.


ive read a little bit about component before, will have a look thanks! 🙂


I think the pattern of using a "regular" function that can then somehow decide to create a real or mock implementation is certainly common. I've no direct experience with Mount, so can't speak to that particular manner of implementing that pattern.

👍 4

I'm still pretty new to spec, and this is the second time I've come across this problem, and I feel like there's a simple solution I'm just missing. In this example, in the ::input spec I need :metrics to be a collection of maps with :name and :value in them. But in the ::output spec I need the same key, :metrics, to be a collection of maps with the same keys but also :type as an additional key.


But I can't call it ::metrics-with-type because then it's looking for the key :metrics-with-type. I need it to be called the same thing but represent something else in the ::output


Not sure what options I have here.


@brandon.ringe That sounds like a use case that spec2 might be better at. (I'm guessing you would define a metrics schema and then for the input you would use a select that says you need just name and value, but for the output you would use a different select that says you need name, value and type.) See Rich's recent talk on it and some documentation on it here


@mfikes Interesting. Thanks a lot.


@brandon.ringe FWIW, spec2 may not yet be suitable for real stuff, and is probably mostly in a state where it can be tried out. (I think it is still being developed.)


Yeah, I'm thinking for now I'll just figure some way around. Possibly renaming the input key, or not using the input spec and just using the output spec with the full set of keys on metrics.


Or rather, removing ::metrics with the input as required, leaving on ::output as the full


Yeah, another workaround would be to make the type an optional key instead of required, and just "hope" that whoever generates output includes that key. If the key does happen to be included, it will be checked for conformance in appropriate places.


Ah yeah. I was thinking about that.


@brandon.ringe :input/metrics and :output/metrics would be two different specs for the same unqualified key :metrics in two different contexts.


@seancorfield thanks! I'll try this out


Has anyone used d3 with clojurescript that can help me solve this interop? I’m trying to use stratify as per this example:

var root = d3.stratify()
    .id(function(d) { return; })
    .parentId(function(d) { return d.parent; })


#((get-in (js->clj %1) [:parent :uuid])) doesn’t quite look right. I think you have too many parens


are you receiving an error of some sort?


TypeError: module$node_modules$d3_hierarchy$dist$ is not a function


Maybe i should just define that function seperately and pass it in?


try wrapping stratify in parens first


-> (d3/stratify)


you are not calling it as a function


it returns #object[stratify] which is a javascript object?


I’m not sure what you mean


in your Js code, you call stratify d3.stratify()


you need to do the same in your CLJS. (d3/stratify)


right now you’re accessing it like a variable in the d3 namespace. like in JS


ahhh that makes sense.


I’ll see what i can do with this thing it returned.



👍 4
Lennart Buit19:04:34

can you give an example?

Lennart Buit19:04:27

but you are basically abstracting(?) over function invocation here

Lennart Buit19:04:00

yeah but you gotta tell clojure somewhere which function you intended to call

Lennart Buit19:04:40

(don’t def inside of a defn, theres let for that)

Lennart Buit19:04:07

(and letfn for defining nested functions)

Lennart Buit19:04:38

ehm, well, the same binding refers to the same value if thats what you are asking

Lennart Buit19:04:16

(let [a (some-terrible-computation)]
  (println a a)
Evals (some-terrible-computation) once

Lennart Buit19:04:30

but okay, you have your nice function, what would you like to abstract of it and why


you can use binding. but I think explicitly taking a fn as an arg (or even just have two functions) is better

Lennart Buit19:04:15

well in this particular case, your golden-mean is a constant (or actually two)

Lennart Buit19:04:29

(was reading up on wiki :P)


in general though what you’re looking for is binding. but there are lots of caveats


it doesn’t work nicely with laziness

Lennart Buit19:04:58

well hard to understand

Lennart Buit19:04:13

because the place where you set the binding is not the place where you are using the value of that binding

Lennart Buit19:04:39

so, it takes one of those magical 7 value slots in our short term memory


readable code is easier to maintain 🙂


IMO binding use should never be part of a user-level API


it should be opaque to the user, part of a larger abstraction

Lennart Buit19:04:50

Thanks for filling in @U4YGF4NGM! I like to add that making something stupidly simple is often worth it

👍 4
Lennart Buit19:04:33

two defs, since its a constant 😉

Lennart Buit20:04:58

yeah the golden ratio

Lennart Buit20:04:05

natures magic constant

Lennart Buit20:04:38

try some of the project euler problems in Clojure!

Lennart Buit19:04:51

It sounds like a … thing that is not really desirable 😛

replied to a thread:can you give an example?

you can use binding. but I think explicitly taking a fn as an arg (or even just have two functions) is better


For someone with little resources. Is there a link or tutorial to help a beginner?


Something that has a guide kind of feel to the learning process.


@sotrhraven absolutely! Clojure for the Brave and True is an excellent resource.


Free to read online.


@jaihindhreddy will check that one out


Also check out Has a bunch of problems that start from the very basic getting progressively harder and more elaborate, and is the most interactive way to learn Clojure IMO


adding it to the list