This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-13
Channels
- # aleph (1)
- # beginners (105)
- # boot (6)
- # cider (9)
- # cljs-dev (61)
- # cljsrn (59)
- # clojure (132)
- # clojure-germany (1)
- # clojure-italy (6)
- # clojure-russia (18)
- # clojure-spec (1)
- # clojure-uk (58)
- # clojurescript (56)
- # core-async (1)
- # cursive (17)
- # datomic (20)
- # docs (1)
- # duct (5)
- # editors (1)
- # emacs (7)
- # events (2)
- # figwheel (7)
- # fulcro (30)
- # graphql (8)
- # jobs (3)
- # leiningen (23)
- # luminus (14)
- # mount (6)
- # off-topic (41)
- # onyx (14)
- # protorepl (2)
- # re-frame (7)
- # reagent (32)
- # shadow-cljs (236)
- # tools-deps (92)
- # unrepl (8)
- # vim (60)
- # yada (1)
@mfikes Thanks. I'm not sure I understand how the original function is actually being replaced though. It looks like it's just using doto
on a newly created function.
@kenny Right. That is about creating the checked fn. Here is where the original is replaced https://github.com/clojure/clojurescript/blob/f55b19b89e98a210a89151f52e67567108c536cf/src/main/cljs/cljs/spec/test/alpha.cljc#L42
Wow, I'm blind. I swear I stared at that function for a solid minute and didn't see that. Thanks 🙂
I’m wondering if the identity of objects returned from sets (when called as a function) is documented. In Clojure, I see:
user=> (def s #{(with-meta [:a] {:n 42})})
#'user/s
user=> (meta (s [:a]))
{:n 42}
In ClojureScript, I see:
figwheel:cljs.user=> (def s #{(with-meta [:a] {:n 42})})
#'cljs.user/s
figwheel:cljs.user=> (meta (s [:a]))
nil
As expected, the set entry still has the metadata:
figwheel:cljs.user=> (meta (first s))
{:n 42}
So I’m curious as to whether this is undefined behavior (and therefore legit), or a bug
@john there’s no difference in the semantics of metadata between Clojure / ClojureScript
Forgot to say… I submitted it here (please let me know if I’ve done something wrong so I can update it): https://dev.clojure.org/jira/browse/CLJS-2736
Issue is here https://github.com/clojure/clojurescript/blob/aac49934f41d89c28bbc021a37878e213566decc/src/main/cljs/cljs/core.cljs#L9106
The solution is something like
(let [array (into-array coll)
k (.indexOf array v)]
(aget array k))
???
or use reduce?
or use loop/recur?how about…
(-lookup [coll v not-found]
(if-let [entry (-find hash-map v)
(key entry)
not-found))
Heh… it occurred to me that hash-sets aren’t the only set. So I just looked at the implementation of PersistentTreeSet, and this is pretty much what that implementation is already doing https://github.com/clojure/clojurescript/blob/aac49934f41d89c28bbc021a37878e213566decc/src/main/cljs/cljs/core.cljs#L9271
Is it worth mentioning that it also occurs when calling get
explicitly, or is that sufficiently implied?
The solution is something like
(let [array (into-array coll)
k (.indexOf array v)]
(aget array k))
???
or use reduce?
or use loop/recur?Is there a way to enabled Spec instrumentation as the very first think that is ran? I am running into an issue where I call st/instrument
in my app's entrypoint but because other namespaces have been loaded and have functions calls that occur immediately, they are not replaced with the spec-checking-fn set by instrument
. This means all initial calls are not instrument
'ed.
If you have some namespace which needs to be initialized (contains function calls evaluated when loaded). You can provide init
function for such namespaces and then have your entrypoint code:
(instrument)
(app.namespace1/init)
(app.namespace2/init)
(app.namespace3/init)
...
That will still not catch initial function calls. Also that'd need to be done for every namespace because every namespace has functions that need to be instrumented. For a large app with 60+ namespaces, that would be quite annoying to have to do.
Yes, that will catch initial function calls if you won't call them immediately but put them into init
function inside of the namespace.
What these functions you need to call in so many namespaces when they're loaded do?
That's exactly the example :preloads
has in the docs: https://clojurescript.org/reference/compiler-options#preloads 🙂
Actually, enabling instrumentation in a preload does not work for my application. None of the symbols are defined when instrument
is called in the preload.
Not sure how enabling instrumentation in a preload would ever work for instrumenting your own code.
I have
(defn my-test
[a b]
(+ a b))
(s/fdef my-test
:args (s/cat :a int? :b int?)
:ret int?)
in a core.cljs
and (prn (cljs.spec.test.alpha/instrument))
in a preload. []
is printed out to the console as the result of the instrument
call. That doesn't seem like the behavior intended, as described in the preloads compiler option doc.I have noticed the same, thanks for bringing it up
@kenny I'm not 100% but I think instrument
changes the actual JS var which means it can only work on things that were defined before instrument
was called
I suggest removing that from the compiler option doc then 🙂
Calling from the entry point is problematic for all function calls that occur before the entrypoint is reached (i.e. global registrations like re-frame's reg-event-*
functions).
https://clojurescript.org/reference/compiler-options#preloads > Developing ClojureScript commonly requires development time only side effects such as enabling printing, logging, spec instrumentation, and connecting REPLs.