This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-06
Channels
- # announcements (1)
- # bangalore-clj (3)
- # beginners (73)
- # boot (1)
- # calva (88)
- # cljdoc (13)
- # cljsrn (1)
- # clojure (65)
- # clojure-finland (1)
- # clojure-spec (14)
- # clojure-uk (1)
- # clojurescript (50)
- # core-async (4)
- # datavis (6)
- # duct (2)
- # figwheel-main (1)
- # off-topic (15)
- # pedestal (16)
- # planck (11)
- # re-frame (3)
- # shadow-cljs (19)
- # yada (3)
@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 😞
eg.
(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 invalidThis 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: https://github.com/stuartsierra/component 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.
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
@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 https://github.com/clojure/spec-alpha2/wiki/Schema-and-select
@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.)
For example, see http://insideclojure.org/2019/03/29/journal/
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.
@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 d.name; })
.parentId(function(d) { return d.parent; })
(table);
#((get-in (js->clj %1) [:parent :uuid]))
doesn’t quite look right. I think you have too many parens
TypeError: module$node_modules$d3_hierarchy$dist$d3_hierarchy.stratify.id is not a function
right now you’re accessing it like a variable in the d3 namespace. like d3.stratify.id(...)
in JS
can you give an example?
but you are basically abstracting(?) over function invocation here
yeah but you gotta tell clojure somewhere which function you intended to call
(don’t def
inside of a defn
, theres let
for that)
(and letfn
for defining nested functions)
ehm, well, the same binding refers to the same value if thats what you are asking
(let [a (some-terrible-computation)]
(println a a)
Evals (some-terrible-computation)
oncebut 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
well in this particular case, your golden-mean
is a constant (or actually two)
(was reading up on wiki :P)
in general though what you’re looking for is binding
. but there are lots of caveats
well hard to understand
because the place where you set the binding is not the place where you are using the value of that binding
so, it takes one of those magical 7 value slots in our short term memory
Thanks for filling in @U4YGF4NGM! I like to add that making something stupidly simple is often worth it
two def
s, since its a constant 😉
yeah the golden ratio
natures magic constant
try some of the project euler problems in Clojure!
It sounds like a … thing that is not really desirable 😛
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. https://www.braveclojure.com/clojure-for-the-brave-and-true/
Free to read online.
@jaihindhreddy will check that one out
Also check out http://4clojure.com 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