This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-09
Channels
- # aleph (16)
- # bangalore-clj (1)
- # beginners (57)
- # cider (4)
- # clara (1)
- # cljs-dev (25)
- # cljsrn (12)
- # clojure (76)
- # clojure-dusseldorf (2)
- # clojure-italy (41)
- # clojure-russia (4)
- # clojure-spec (3)
- # clojure-uk (122)
- # clojurescript (101)
- # cursive (8)
- # data-science (30)
- # datomic (2)
- # emacs (2)
- # figwheel (10)
- # fulcro (53)
- # garden (5)
- # gorilla (6)
- # hoplon (1)
- # jobs (1)
- # juxt (14)
- # leiningen (12)
- # om (1)
- # om-next (1)
- # onyx (21)
- # pedestal (40)
- # perun (5)
- # portkey (2)
- # re-frame (16)
- # reagent (1)
- # ring-swagger (3)
- # rum (6)
- # shadow-cljs (239)
- # spacemacs (10)
- # specter (9)
- # uncomplicate (2)
- # unrepl (1)
- # vim (13)
- # yada (16)
I'm guessing there is an easy way to escape [:span "×"] in cljs hiccup. Anyone know of one?
@stvnmllr2 In reagent I've done the following [:span {"dangerouslySetInnerHTML" {"__html" "×"}}]
@stvnmllr2 You might want to look at 2.0.0-alpha1 -- I know safe HTML by default is planned for 2.0.
(I assume the 2.0 Hiccup does both clj and cljs but didn't check)
@tkjone I use loop when I want to juggle a little state while iterating. hth
It does help! Do you have an example I could reference?
if you are consuming a collection in order, reduce is simpler and performs better, FYI. It can only use one accumulator, but you can use a collection and hold multiple values in the accumulator.
Sorry, @tkjone, just saw this. Hope my code-quoting works:
(let [elts [1 2 3 5 7 4 6 8 5]]
(loop [wall false
[e & more] elts]
(let [new-wall (if (even? e) (not wall) wall)]
(when new-wall
(println :wall-is-true new-wall e))
(recur new-wall more))))
Your requirements were trickier than I realized, btw, but that should give you an idea.
the reduce version of that is
(reduce (fn [wall e]
(let [w (if (even? e) (not wall) wall)]
(when w
(println :wall-is-true w e))
w))
false
[1 2 3 5 7 4 6 8 5])
Is there a "standard" approach to set up a rdbms schema (e.g. postgresql) the first time an app is run?
@vinai https://www.clojure-toolbox.com/ Database Migrations I've used migratus and Ragtime
I found today a really weird behaviour with insert-multi! and Redshift jdbc driver. If I give to insert-multi! two rows like [["id1" 1.1] ["id2" 2.2]], I get values 1.1 and 2.2 in Redshift. But if I give rows [["id1" 1] ["id2" 2.2]] then I get values 1 and 2 (not 1 and 2.2) in Redshift. I was wondering that this should probably not be the default behaviour (the first row is used to interpret the type of columns or something weird like that)?
@vinai I don't know if I understand your question correctly but it seems you're looking for a nice pattern to keep db connection self contained. If that's the case I would recommend Stuart Sierra's component.
@rinaldi Thanks, I am using component - I was just wondering about setting up the schema. At the moment I was simply calling a "create table fi not exists..." in the component start. It works okay, but somehow it felt ... off. Can't put my finger on why really.
On that note - how do you prefer to serialize edn for storage (for example in a db table). JSON and keywordize-keys? prn-str and clojure.edn/read? transit?
+1 on transit - it’s not recommended for long term storage but it round trips, and it’s extensible with local rather than global config (another huge bonus)
What are the downsides of prn-str
and clojure.edn/read-string
though? Not trying to avoid transit here, only wondering...
@U051SS2EU I've using transit to send data over the wire and it works great. But I don't understand the local vs. global config. Can you give me a pointer to local vs global extensibility config for transit?
sure - with read-string, to define a data reader / writer for a new type that previously wasn’t readable as edn, you need to modify clojure’s global *data-readers*
and the global clojure.core/print-method
multimethod - you can’t define a printer / reader combo local to one context
with transit, there’s an optional key called :handlers
, and another called :default-handler
and those control how things are read or written in local scope
That might be naive but what came to mind is that delay
might be helpful?
From the docs:
>Takes a body of expressions and yields a Delay object that *will invoke the body only the first time it is forced* (...)
If I have an anonymous function with several when forms, is there a way to break? For example:
(fn []
when condition
expression 1
expression 2 ;; <-- break here - don't try to evaluate the next when
when condition
expression 1)
no. Clojure is a functional language, and breaking is an imperative construct - you would have to wrap both when
s in an appropriate if
if you want to branch
Yikes. Imperative programming throwing me off the path again. Given this situation, here is what my code looks like. Is there a better way to handle this?
(reduce (fn [inBetween element]
(p "")
(p "break")
(when (or (identical? element this) (identical? (get @appState :lastChecked) element))
(p "1")
(set! (.. element -checked) true)
(not inBetween))
(when (true? inBetween)
(p "2")
(set! (.. element -checked) true)
true)
(when (false? inBetween)
(p "3")
false))
false
(get-checkboxes)))
I also wrote the above in cond
etc but because I want to use side-effects, I figured the when
would be more appropriate given that it is wrapped in a do
if you only want one of the cases to run, cond with do is probably more appropriate
Good point. @rinaldi would condp
work in this scenario as my predicate
is different for each case?
I tend to use condp
for situations where I want to react to specific values. Not sure if it suits your needs but came to mind when reading through your snippet.
Okay, implemented a solution https://github.com/tkjone/clojurescript-30/tree/master/12-check-multiple-checkboxes If there are interested parties, this is a very small program and I would be very interested to learn if there are ways to improve this and make it as idiomatic as possible
is this normal behavior?
(defn foo [profile]
(let [name (str "foo-" (name profile))]
(prn name)))
i get error
ClassCastException java.lang.String cannot be cast to clojure.lang.IFn auto-service-jobs.core/create-healthcheck-job (form-init20863580730528680.clj:206)
how do you write tests when working with tokens
so i have tokens.edn
where i get all my tokens
anyway i wanna test my function but it uses token from that file
and i dont wanna put token in my test
should i put token as parameter ?
@lepistane Perhaps you want to mock the part of your function that reads from the file?