Fork me on GitHub
#beginners
<
2020-08-16
>
Trung Dinh03:08:57

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

chucklehead03:08:10

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 possible

Trung Dinh04:08:40

Thanks, I’m actually looking for the general solution, guess I’ll have to build the vector with reduce first then….

chucklehead04:08:15

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

dpsutton03:08:56

Can you explain what you’re trying to do?

Trung Dinh04:08:34

I’m just trying possible ways on how destructuring work 🙂

dpsutton04:08:23

Do you know how to destructure a single map?

Joe15:08:03

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.

valtteri19:08:21

Hi, closure library provides quite comprehensive formatters for various use-cases. Check out https://google.github.io/closure-library/api/goog.i18n.NumberFormat.html

valtteri19:08:21

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 €"

Joe19:08:48

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

hoopes18:08:38

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)

jamesleonis20:08:04

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

bigos22:08:33

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

bigos22:08:21

In other words how do i copy working code from repl to a file?

Ty23:08:43

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.

Ty23:08:09

(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)))

seancorfield23:08:42

@tylertracey09 Parentheses are very important in Clojure: they indicate function calls, for example, and you're missing those around most of your calls.

seancorfield23:08:48

(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 ...)

seancorfield23:08:26

@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.

seancorfield23:08:50

Looking at that repo, it's very hard to know what you're actually attempting to do.

seancorfield23:08:26

If you want to look at deps.edn-based Ring app, this may help https://github.com/seancorfield/usermanager-example/

bigos23:08:29

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

bigos23:08:26

btw I was looking @seancorfield tutorials about using deps.edn instead of using lein.

Ty23:08:01

Thanks, Sean

Ty23:08:33

Does anyone use Calva with VS Code?

Ty23:08:54

I'm trying to figure out if there's a way to do something like evaluate the expression under the cursor

Ty23:08:14

Or perhaps open the current file in a repl quickly

chucklehead23:08:19

ctrl+alt+c,enter will load the current file in the repl, ctrl+alt+c,v will eval the current form to repl

chucklehead23:08:00

ctrl+enter will also eval current form

pez04:08:52

alt+enter will evaluate the top-level form

seancorfield23:08:05

@tylertracey09 The #calva channel will be a great place for you to get in depth help with that combo.