This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-02
Channels
- # adventofcode (47)
- # announcements (7)
- # aws (1)
- # babashka (52)
- # beginners (80)
- # boot (3)
- # calva (19)
- # cider (9)
- # cljs-dev (1)
- # clojure (48)
- # clojure-brasil (1)
- # clojure-dev (27)
- # clojure-europe (3)
- # clojure-madison (3)
- # clojure-nl (29)
- # clojure-spec (11)
- # clojure-sweden (1)
- # clojure-uk (49)
- # clojurescript (66)
- # core-async (20)
- # cryogen (4)
- # cursive (13)
- # data-science (7)
- # datomic (5)
- # emacs (30)
- # figwheel-main (11)
- # fulcro (15)
- # graphql (8)
- # jobs (5)
- # joker (17)
- # lambdaisland (1)
- # leiningen (2)
- # malli (2)
- # off-topic (5)
- # pathom (22)
- # re-frame (12)
- # reagent (29)
- # reitit (2)
- # ring (10)
- # shadow-cljs (57)
- # specter (3)
- # tools-deps (22)
- # vim (5)
- # xtdb (7)
Hi All, can anyone help me out with, how we can debug clojurescript in visual studio ? Please share steps if possible. Thanks.
I've heard good things about https://purelyfunctional.tv/
I don't know of any free video courses. This book is free however https://www.braveclojure.com/
Thank you... but any free resource available
Is it okay for a predicate to return truthy/falsy values? Or they should always return true/false?
(defn repeated-first? [[first & rest]]
(some #{first} rest))
(repeated-first? [1 2 35 6 1])
;; => 1
(repeated-first? [13 2 35 6 1])
;; => nil
Always up to you but I think most would be surprised to see the question mark on the end of that and no Boolean.

I can write code using a loop and transient, but there might be something more straightforwardā¦
(into {} (map-indexed (fn [i e] [i e]) [:hey :there :buddy]))
=> {0 :hey, 1 :there, 2 :buddy}
Thanks! I believe, you can shorten it to (into {} (map-indexed vector [:hey :there :buddy]))=> {0 :hey, 1 :there, 2 :buddy}
zipmap takes a key seq and a val seq and zips them up (and stops at end of first finite seq)
[:> Dialog {:full-screen true :open @show-login-screen? :on-close #(dispatch [:show-login-screen false])
:Transition-component [:> Slide {:direction "up"}]}
What is the :>
symbol in that code? Is that something the community has standardized for something, something from Reagent?I posted an incorrect answer yesterday-- :>
is the syntactic sugar for reagent/adapt-react-class
, see under āCreating Reagent Components from React Componentsā at http://reagent-project.github.io/docs/master/InteropWithReact.html
it's up to the library that is inspecting that datastructure to decide what it means. In this case, I believe that is something special in Reagent
I believe :>
is syntactic sugar for reagent/create-class http://reagent-project.github.io/docs/master/reagent.core.html#var-create-class
This is incorrect-- :>
is the syntactic sugar for reagent/adapt-react-class
, see under āCreating Reagent Components from React Componentsā at http://reagent-project.github.io/docs/master/InteropWithReact.html
Is there somewhere that I can find the documentation about :>
related to create-class
or is that just common knowledge?
@UCQL6E7PY Thank you!
@UCQL6E7PY On a similar note, do you know where I can find documentation on :<>
as well?
Hereās the pull request where they were added! Looks like itās short hand for a React Fragment https://github.com/reagent-project/reagent/pull/352
Just FYI, to find the first one I searched āreagent colon greater thanā on google, and for the 2nd one I went to the Reagent changelog and CTRL-Fād for :<>
.
Just mentioning my method in case you run into more special keywords that donāt have easy to find documentation
@UGMAVSMUM
@UCQL6E7PY Thanks for the assist! They were certainly difficult ones to find so I appreciate you sharing your search methods
Iām working on a test case with clojure.test but when I try to run code in my REPL itās giving me an error because my database spec is empty. I see some setup at the top of the test file that seems to set up mock data. For example: (use-fixtures :once #'fix/global-fixture)
with global-fixture
being defined as:
(defn global-fixture
"should be used in every test namespace"
[f]
(binding [*test-context* {::db/pool (mk-pool) ::conf/config test-config}]
(log/with-level :error (f))))
So in my code, to get the database spec I have (::db/pool fixtures/*test-context*)
. So, my question is, how can I initialize all of those fixtures in the REPL so that I can call my function with a spec that doesnāt eval to nil
?how do you run the test code?
take a look at https://clojure.github.io/clojure/clojure.test-api.html#clojure.test/test-vars
I use vim-fireplace so usually I do cpr
to run all the tests or :.RunTests
on one of the test to run just that one.
if you call the test as if it were a function, you can pass it as an arg to the fixture, otherwise if using clojure.test functions the fixture should be applied already
it depends which functions you call
So, hereās an example test I have:
(deftest checking-something
(let [id (data.stuff/first-id (::db/pool fixtures/*test-context*))]
(testing "something"
(is (= id 99)))))
And I can run that test with cpr
to run all the tests and theyāll run just fine. But if put my cursor over (data.stuff/first-id (::db/pool fixtures/*test-context*))
and type cpp
to just run that one function in the REPL it fails because (::db/pool fixtures/*test-context*)
evals to nil
.Actually, Iām wrong. cpr
also gives me an error. Both basically saying that test-context is nil or null.
right, because in both cases you are running a function, not a "test", per se, so the fixture isn't applied
see @alexmillerās link above - there should be something in fireplace that hooks into that as well
hmm, cpr
should be applying the fixture
Iām getting Unable to resolve symbol: test-vars in this context
when I run (test-vars fix/*test-context*)
. Is that the wrong way to run it?
it's clojure.test/test-vars
So, I should be able to run test-vars
(GOD does Slackās new markdown handling suck) and then run, for example; (::db/pool fix/*test-context*)
and get something more than nil
?
if ::db
aliases the same ns in your test ns as it did in the fixture ns
perhaps it would help to look at what fix/**test-context**
is
Itās initially defined as (def ^:dynamic *test-context* {})
but then global-fixture
seems to set it up:
(defn global-fixture
"should be used in every test namespace"
[f]
(binding [*test-context* {::db/pool (mk-pool) ::conf/config test-config}]
(log/with-level :error (f))))
Which makes me question whether global-fixture
is getting called within my repl. Iād think so since I have (use-fixtures :once #'fix/global-fixture)
in my test file.you are doing the things that ensure any fixtures get invoked, which is why I suspected it might be you are using the wrong key
you could eg. (print (keys fix/**test-context*))*
this new wysiwyg editing mode for inline source is terrible
what happens if you call the fixture by hand with your test function as an argument?
it could be the fixture is broken also
Except that they are because tests that use, for example, fix/*test-context*
that were written by someone else are passing.
any chance you are calling something lazy in your test, so that by the time the value is forced the context binding the values has exited?
that's not the case in your example, but it's definitely a gotcha with dynamic bindings
I moved (print (keys fix/*test-context*))
to right after the use-fixtures
call and still get nil
.
that's not the right place to use it - put it inside the test code itself
code at the top level will never be run inside the fixture
@darrell this is my attempt at a minimal demo of how it works properly
foo$ clj
Clojure 1.10.0
(cmd)user=> (require '[clojure.test :as test :refer [deftest is test-vars use-fixtures]])
nil
(cmd)user=> (def ^:dynamic *foo* nil)
#'user/*foo*
(cmd)user=> (deftest foo-test (is (= *foo* 2)))
#'user/foo-test
(cmd)user=> (test-vars [#'foo-test])
FAIL in (foo-test) (NO_SOURCE_FILE:1)
expected: (= *foo* 2)
actual: (not (= nil 2))
nil
(cmd)user=> (defn foo-fixture [f] (binding [*foo* 2] (f)))
#'user/foo-fixture
(cmd)user=> (test/use-fixtures :once foo-fixture)
#:clojure.test{:once-fixtures (#object[user$foo_fixture 0x5c00384f "user$foo_fixture@5c00384f"])}
(cmd)user=> (test-vars [#'foo-test])
nil
(ins)user=> ^D
Thanks @U051SS2EU! Iāll take a look and apologies for the delayed reply. I had to step away for a few hours.
@glfinn83 What do you mean by "debug"?
(I get the impression that very few Clojure devs use a "traditional" (i.e., step) debugger -- but instead use a variety of REPL-based techniques)
off-tangent but, I've found that Spacemacs' CIDER has a step-debugger that just works
FWIW, I haven't used a step debugger for maybe two decades now -- and I've never felt the need for it in Clojure.
yea I've found this to be the case too. It's so much easier to reason about your code and I think thats how it should be. Although, one thing that trips me up sometimes is holding the types in my head (since, dynamic typing). Any tips to overcome that?
I don't know. I just don't find that to be a problem. In what sort of situations do you find that to be a problem?
(I used to rely on a step debugger when I did C++ and I used them a little when I first got started with Java in the late 90's but not since)
Exactly what Raf said. Using REPL is nice, but it would also be good to be able to step through running code.
VScode is actually my main editor but Calva was conflicting with my vim keybindings, so I decided to give Spacemacs a try. Really great so far (for Clojure, at least)
Cider's debugger is pretty sweet. Its not exactly like a traditional debugger, and can't debug into Java code, but I recommend trying it out if you use Cider. Check it out: https://docs.cider.mx/cider/debugging/debugger.html