This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-16
Channels
- # atom-editor (6)
- # babashka (31)
- # beginners (34)
- # calva (1)
- # cider (21)
- # clj-kondo (5)
- # cljsrn (2)
- # clojars (6)
- # clojure (35)
- # clojure-europe (3)
- # clojure-norway (2)
- # clojurescript (4)
- # conjure (10)
- # cursive (8)
- # data-science (78)
- # fulcro (23)
- # graphql (10)
- # helix (2)
- # luminus (1)
- # off-topic (50)
- # other-languages (1)
- # pathom (8)
- # re-frame (9)
- # reagent (9)
- # reitit (1)
- # rewrite-clj (6)
- # shadow-cljs (134)
- # tools-deps (53)
- # vscode (1)
- # xtdb (4)
hi, wrapping my head around destructuring… not sure how to get all :val in a vector of maps, e.g
(def maps-in-vector [{:name "n1" :val 1} {:name "n2" :val 2} {:name "n3" :val 3}])
I’ve looked through some resources (such as https://gist.github.com/john2x/e1dca953548bfdfb9844 , or Russ Olsen’s book, but haven’t found yet…, can anyone please help? Thanks
so something like this will work explicitly for a 3-element vector:
(fn
[[{val-1 :val} {val-2 :val} {val-3 :val}]]
(println val-1 val-2 val-3))
but if you're looking for a more general solution where you'd have some destructured vals
that was automatically [1 2 3]
I don't think that's possibleThanks, I’m actually looking for the general solution, guess I’ll have to build the vector with reduce first then….
if it doesn't have to be in the destructure I think (mapv :val maps-in-vector)
will give you the actual values you want
I’m just trying possible ways on how destructuring work 🙂
I think I got the answer here https://clojurians.slack.com/archives/C053AK3F9/p1597549750448300?thread_ts=1597549017.447600&cid=C053AK3F9 , thanks
Is there a way to comma-format numbers with specifiers in clojurescript? In Clojure I'd use (format "%,d" num)
but trying that with the goog.string
library doesn't work. I'd have thought this would be easy to google, but no luck.
Hi, closure library provides quite comprehensive formatters for various use-cases. Check out https://google.github.io/closure-library/api/goog.i18n.NumberFormat.html
It’s not trivial to use but hope you get the idea
cljs.user> (require '[goog.i18n.NumberFormat])
nil
cljs.user> (require '[goog.i18n.NumberFormatSymbols_fi])
nil
cljs.user> (def fi goog.i18n.NumberFormatSymbols_fi)
#'cljs.user/fi
cljs.user> (set! js/goog.i18n.NumberFormatSymbols fi)
#js {:DECIMAL_SEP ",", :GROUP_SEP " ", :PERCENT "%", :ZERO_DIGIT "0", :PLUS_SIGN "+", :MINUS_SIGN "−", :EXP_SYMBOL "E", :PERMILL "‰", :INFINITY "∞", :NAN "epäluku", :DECIMAL_PATTERN "#,##0.###", :SCIENTIFIC_PATTERN "#E0", :PERCENT_PATTERN "#,##0 %", :CURRENCY_PATTERN "#,##0.00 ¤", :DEF_CURRENCY_CODE "EUR"}
cljs.user> (def fmt (new goog.i18n.NumberFormat goog.i18n.NumberFormat.Format.CURRENCY))
#'cljs.user/fmt
cljs.user> (.format fmt 13.20)
"13,20 €"
That looks great, thanks very much! Surprised that doesn't come out the box, I would've thought it's a very common use case
is there an obvious reason why clojure.tools.namespace.repl/refresh
(or refresh-all
) would not reload changed files when i'm running from within a docker container? do i have to own the files as well (my uid is different in the container)
I've run into this when I had to run Docker through a virtual machine. It doesn't pick up that the files changed inside the container. However IIRC this was only for the refresh
and not refresh-all
When I run my code in clj -repl my code works, but when I put it in a file I get all sorts of errors that I do not understand https://github.com/bigos/apireport this is my code
I'm doing some katas to begin my clojure journey. I'm getting an error about being unable to take the value of a macro from the following code.
(ns multiples)
(defn divisible-by? [x d]
true? (= (mod x d) 0))
(defn condition? [n]
or (divisble-by? n 3) (divisible-by n 5))
(defn solution [number]
reduce + (filter condition? (range number)))
@tylertracey09 Parentheses are very important in Clojure: they indicate function calls, for example, and you're missing those around most of your calls.
(ns multiples)
(defn divisible-by? [x d]
(= (mod x d) 0)) ; don't need true? here since = already returns boolean
(defn condition? [n]
(or (divisible-by? n 3) (divisible-by? n 5))) ; need parens around use of (or ...)
(defn solution [number]
(reduce + (filter condition? (range number)))) ; need parens around use of (reduce ...)
@ruby.object Folks won't really be able to help you unless you can explain what exactly you tried and what errors you are seeing.
Looking at that repo, it's very hard to know what you're actually attempting to do.
If you want to look at deps.edn
-based Ring app, this may help https://github.com/seancorfield/usermanager-example/
I have solved the problem https://github.com/bigos/apireport/commit/ca4ab73d824f4ffa51466c24961aa0fed818d5c1
I was trying to move the code that works in clj -repl to a file in the tasks folder and can be run with clj -A;tasks without the need to write a sequence of command in terminal repl
btw I was looking @seancorfield tutorials about using deps.edn instead of using lein.
I'm trying to figure out if there's a way to do something like evaluate the expression under the cursor
ctrl+alt+c,enter will load the current file in the repl, ctrl+alt+c,v will eval the current form to repl
ctrl+enter will also eval current form
@tylertracey09 The #calva channel will be a great place for you to get in depth help with that combo.