This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-25
Channels
- # aleph (1)
- # beginners (72)
- # boot (3)
- # cider (28)
- # cljs-dev (193)
- # cljsrn (11)
- # clojure (73)
- # clojure-brasil (3)
- # clojure-gamedev (2)
- # clojure-russia (6)
- # clojure-spec (30)
- # clojure-uk (26)
- # clojured (1)
- # clojurescript (32)
- # code-reviews (9)
- # core-async (4)
- # datascript (5)
- # datomic (9)
- # dirac (38)
- # fulcro (23)
- # garden (11)
- # leiningen (1)
- # luminus (11)
- # lumo (6)
- # off-topic (17)
- # quil (2)
- # re-frame (2)
- # reagent (3)
- # ring (3)
- # shadow-cljs (12)
- # spacemacs (4)
- # sql (2)
- # unrepl (85)
- # vim (3)
Very new to clojure/clojurescript and working on my first exercise
I have a problem concerning re-com
and reagent
rendering.
I have this view function (using re-frame
):
(defn tile-test []
(let [dim 2]
[v-box
:children
(for [i (range dim)]
[h-box
:height "100px" :width "100%"
:children
(for [j (range dim)]
(let [num (+ (* i dim) j)]
[title :label num :level :level2 :style {:flex "1 1 flex !important"}]))])]))
But when rendered, 1 1 flex !important
for :flex
value is replaced with 0 0 auto
. I can’t figure out what goes wrong here. Trying to debug clojurescript is a pain also - perhaps I’m not doing it right.
I’ve been stuck for a while here. Any help is appreciated.@duminda I think it is because “1 1 flex” is an invalid flex-basis. you probably want “1 1 auto”. you really shouldn’t need the “!important”
(defn map-contains
"Does `m` contain at least the keys in `min-keys` with a value of at
least the value in min-keys?"
[m min-keys]
(loop [min-keys min-keys]
(cond
;; Base case: we've exhausted min-keys.
(empty? min-keys) true
;; If the value in m for this key is less, we're not included.
(let [[c count] (first min-keys)]
(< (get m c 0) count))
false
;; This key is fine, check the rest.
:else (recur (rest min-keys)))))
it's very good but you could use reduce
test cases:
cljs.user=> (map-contains {:a 1 :b 2} {:a 1 :b 2})
true
cljs.user=> (map-contains {:a 1 :b 2} {:a 1 :b 3})
false
cljs.user=> (map-contains {:a 1 :b 3} {:a 1 :b 3 :c 1})
false
that being said, the name is very counterintuitive, since it does a comparison of the vals and assumes they are numbers
yep, that version is definitely better than reduce
🙂
sure
cljs.user=> (update {:a 1} :a inc)
{:a 2}
also:
cljs.user=> (update-in {:a {:b 1}} [:a :b] inc)
{:a {:b 2}}
aha, update
is what I want. I found update-in
but that seems less useful when you're only interested in a single key.
I need to make a large number of http requests and then merge the results into a large map at the end (order is important). However, to save time I would like downloads to proceed in parallel (say, two simultaneous downloads at a time). Is core.async the right way to go here? If so, is there a good example for this use case?
I think do. Most http libraries are async by default. Did some cljs pet project before, where 8 http request needed to be combined, which was quite easy. So I guess with a pool of 2 you get what you want.
@feihong.hsu core.async is useful for coordinating asynchronous data, but there are gotchas for using it directly for parallelism - a good rule of thumb is to put your IO or CPU heavy code in core.async/thread and then use the channel returned by thread
or if your http library has a switch for async, you can use core.async in the callback to simplify coordinating all the data as it's available
hi i'm trying to figure out one clojurekoans task: how to evaluate this? (= 25 ( __ (fn [n] (* n n)))) thx 🙂
(= 25 ((fn [f] (f 5)) (fn [n] (* n n))))
@shulc_ what you need is a function that accepts a function, and returns 25
it was a bit puzzling but @joelsanchez @noisesmith got it 😄
In http://www.4clojure.com (a great learning resource), you can see others' solutions, and it is interesting how often the solutions are "cheats" 🙂
the cheat solution here could be (constantly 25)
for example
I'd argue even the cheat would show that understand the thing the lesson is asking for though
user=> (map (constantly 25) [0 nil inc {} "hello"])
(25 25 25 25 25)
@duminda I think it is because “1 1 flex” is an invalid flex-basis. you probably want “1 1 auto”. you really shouldn’t need the “!important”
hey all, I'm having some trouble using cljs-http
I add it as a dependency in project.clj
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.8.51"]
[org.clojure/core.async "0.2.395"]
[io.nervous/cljs-lambda "0.3.5"]
[cljs-http "0.1.44"]]
:plugins [[lein-cljsbuild "1.1.4"]
[lein-npm "0.6.0"]
[lein-doo "0.1.7"]
[io.nervous/lein-cljs-lambda "0.6.6"]]
:npm {:dependencies [[source-map-support "0.4.0"]]}
and run lein deps
and then I want to call it from a function that I have, but call it from the repl
so I load it in my file
(ns jim-stuff.core
(:require
[cljs.core.async :as async]
[promesa.core :as p])
(:require-macros [cljs.core.async.macros :refer [go]]))
and I try to use planck for cljs repl
with lein dependencies
planck -c $(lein classpath)
But it gives me this error
No such namespace: java.util.concurrent.locks.Lock, could not locate java/util/concurrent/locks/Lock.cljs, java/util/concurrent/locks/Lock.cljc, or JavaScript source providing "java.util.concurrent.locks.Lock" in file cljs/core/async/impl/ioc_macros.clj
Some strange java.util.concurrent.locks.Lock
error
Why is it even trying to use java stuff for cljs?
Could be something going wrong with async, as cljs-http is also using it. Maybe because you only refer to go? I would take a look at the cljs-http source and how async is used in there.
hmm I am getting a warning, "unable to resolve get"
(go (let [response (<! (http/get ""
{:with-credentials? false
:query-params {"since" 135}}))]
(prn (:status response))
(prn (map :login (:body response)))))
I changed the core.async require to [cljs.core.async :as async :refer [<!]]
but I shouldn't need to specifically require http/get right?
@derpocious For self-hosted core.async
see this port https://github.com/mfikes/andare
@derpocious - to be clear, you need to refer to http at least (which I didn't see in your ns snippet)
@derpocious Also, if you happen to be targeting Planck, it has a built-in HTTP implementation. http://planck-repl.org/planck-http.html
@noisesmith sorry, I am requiring that too
[cljs-http.client :as http]
OK - the other thing is that I thought it was called GET but I could be misremembering
@mfikes so I can use andare instead of cljs-http?
@derpocious No. Andare is a replacement of core.async
for self-hosted
hmm it says unsable to resolve GET as well
@derpocious But, if you are using Planck (dunno if you are in the end), Planck has a built-in planck.http
namespace you can use instead of cljs-http
. And planck.http
delegates to libcurl
. I doubt cljs-http
could work in Planck (I don't see how it would make outbound network requests.)
that's very strange - it is actually get (I double checked)
hmm ok I need to look into this more. thanks guys 🙂
hey @mfikes, I still don't really understand what the point of planck.http is
I'm writing a cljs function that will be deployed to aws lambda which uses cljs-http
And I would like to try it out by calling it from a cljs repl, but you are saying I can't do that?
Is there a way to tell it to swap cljs-http for planck-http while I'm in the repl without having to change my code to deploy?
@derpocious If you want to make an outbound HTTP call (say, a get
) from Planck, you can use planck.http
@derpocious Presumably your are not using Planck in your AWS, but some code that deploys onto Node?