This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-31
Channels
- # aleph (9)
- # bangalore-clj (1)
- # beginners (115)
- # cider (16)
- # clara (20)
- # cljs-dev (47)
- # cljsrn (50)
- # clojure (70)
- # clojure-dusseldorf (2)
- # clojure-italy (16)
- # clojure-sanfrancisco (1)
- # clojure-spec (9)
- # clojure-uk (37)
- # clojurescript (132)
- # cursive (21)
- # datomic (36)
- # dirac (53)
- # fulcro (34)
- # graphql (6)
- # hoplon (96)
- # jobs (2)
- # juxt (2)
- # keechma (2)
- # leiningen (5)
- # off-topic (3)
- # om (2)
- # om-next (3)
- # parinfer (3)
- # re-frame (17)
- # remote-jobs (1)
- # shadow-cljs (57)
- # specter (12)
- # sql (43)
- # unrepl (11)
- # yada (5)
Hi! Any ideas how I can improve this code? My gut feeling is that there is a more elegant way 🙂
(update data :product-users
(fn [a] (map (fn [b] (update b :new-phone-number boolean-to-norwegian)) a)))
one improvement but still not perfect:
(update data :product-users
#(map (fn [b] (update b :new-phone-number boolean-to-norwegian)) %))
(letfn [(update-user [user]
(update user :new-phone-number boolean-to-norwegian))]
(-> data
(update :product-users (partial map update-user))))
interesting. didnt know letfn
existed. and I am going to read what partial
does 😄 thanks for the input!
(partial map update-user)
is equivalent to #(map update-user %)
although, to be honest, I'd def
update-user
@karl.jakob.lind what does the data structure look like?
@karl.jakob.lind Are you up for specter? It should be super easy with it
:thumbsup: will look into it, but dont think i will include another dependency just for this.
that was short, but think it will be too confusing learning clojure and that library simultaneously 🙂
hi there, how would you handle a POST- or PUT-request with a named parameter in compojure like this? (PUT "/api/article/:slug" [slug request] (update-article! slug request)))
ok...easy: (PUT "/api/article/:slug" {:keys [route-params params]} (update-article! article-params params))
@timok here are the details of Compojures destructuring: https://github.com/weavejester/compojure/wiki/Destructuring-Syntax
Guys, what this means langohr.core/*default-config*
, those *
?
It's not a special characters per se, just a convention that usually used to indicate a dynamic vars. You can read more about it here https://clojure.org/guides/weird_characters#__code_var_name_code_earmuffs
Hello everyone, I want to ask what is the safe yet idiomatic way to cast a string into boolean?
I have query param in a ring application which is supposed to be a boolean flag. Since all query params' value is a string, I need to properly cast "false"
into false
.
@hawari.rahman17 i would just use a cond
@hawari.rahman17 (Boolean/parseBoolean "false")
also does the trick
Alright, thanks @U61HA86AG!
has anyone had luck using any of the lein-sass plugins? i have a /sass/site.scss
file and a /some/dir/bootstrap.scss
file. site.scss
has an import statement: @import "../some/dir/bootstrap"
which produces the following sass error: file to import not found or unreadable: ../some/dir/bootstrap
. manually compiling the scss works just fine though. any thoughts?
I was having the same issue recently, switched to lein sassc
instead https://github.com/apribase/lein-sassc
as someone switching from less, is there a way to install sassc without having to build it from source (linux / osx)?
ah okay, it works! thanks @manutter51
Hi all, I’m wrecking my head on this and I’m hoping you can offer me some pointers. At its simplest level, let’s say I have a ‘dumb’ container component, e.g.: `(defn my-component [content] [:div content])` … and a (possibly arbitrarily nested) tree structure, e.g.
(def tree [["a" ["b" "c" "d"]] "e"])
What approach would you use to walk the tree, plug-in the component and its content to return something like this?
(def result [:div
[:div "a"
[:div "b"]
[:div "c"]
[:div "d"]]
[:div "e"]])
(My naive implementation has the component recursively calling itself on the children, which I really don’t want.)
Do I need a zipper for this, or is there some other way to accomplish it? Thanks so much in advance!@cperrone a zipper could work but might be overkill. maybe check out postwalk
? you could use it to build up the component markup in one go https://clojuredocs.org/clojure.walk/postwalk
Mmm I had a look at postwalk but the examples I saw weren’t of much help as I needed to modify the structure a bit and postwalk seemed only ok for basic node replacement. (In fact I was using vectors and maps originally, so I knew I was going to change the structure). I’ll have a look again.
it was just an impulsive suggestion and i'm not entirely sure it will solve your problem. 😉
the last time i used specter in a cljs project it blew up the project size by a couple hundred kb, but that was 6+ months ago. any idea if that has improved?
if it’s still a problem you should open an issue for it, I’m sure nathan would be interested in taking a look at that
yes, he even asked me to send some extra information but i never found the time. oopsies.
@cperrone yeah, that's pretty simple with clojure.walk/postwalk
something like this (I think, it's untested):
(walk/postwalk
(fn [itm]
(if (sequential? itm)
(into [:div] itm)
[:div itm]))
data)
thanks @tbaldridge! It’s “almost” there:
[:div [:div
[:div "a"]
[:div
[:div "b"]
[:div "c"]
[:div "d"]]]
[:div "e"]]
but at least I can play with it a little more. a wraps b c d, e is at the same level of aHello, I have pretty good experience with clojure but little to none with clojurescript. I’m using the guide from cemerick/piggieback to test stuff out but for some reason everyone is referencing the js
namespace but for some reason my configuration doesnt load it? My first thought is that it requires the repl to be connected to a broswer but that doesn’t make sense either. Any help is appreciated.
js
is not a usual clojurescript namespace. It is a bridge between cljs and JavaScript runtime which give you ability to get access to global runtime variables. Like this - (js/console.log "some message")
or (js/alert "Some alert message")
. In those examples console.log
and alert
are functions defined in global runtime scope. If you want to use those functions - your repl should be started in the context of clojurescript which means - connected to javascript runtime (node or browser).
@gganley https://lambdaisland.com/guides/clojure-repls/clojurescript-repls there is good description of difference between rhino, node and browser backends for clojurescript
the js runtime is the only way cljs can run - cljs creates js code, and using js/foo is how you directly engage with things in the js engine running your code, outside the cljs abstractions themselves
it's like your escape hatch to access the regular vm, and can do anything javascript can
It makes sense that it is the interop layer, but for some reason when I run cider-clojurescript-jack-in
I can run commands like (+ 1 1)
and the macroexpand is proper cljs a la (js* "(+ {} {})" 1 1)
or something but js
is not a bound symbol
oh, js* is totally different
the * is part of the name here
I meant to show that I’m in a clojurescript environment and not a clojure environment
right, js
does not exist, js/window
etc. do
just as clojure.core
does not exist, but clojure.core/+
does, etc.
(similar but not the same mechanism)
I guess a better way to put that is that namespaces and packages are not first class
something along those lines yes but unlike that example I can’t just (require [cljs.js :as js])
or whatever it would look like
right, that's invalid require syntax
(require '[cljs.js :as js])
but then that would clash with the built in js/foo
syntax, so don't use that specific :as binding
perhaps I am missing your actual issue and getting caught up in the wrong semantic questions, sorry
@gganley what happens when you type (js/console.log "Hello, world")
in your ClojureScript REPL?
minor nitpick - that syntax works but it's accidental that it does, (.log js/console "Hello, world")
is the more canonical form (and there are cases where you can get a much better error message for eg. shadowed js globals if you use that syntax)
I know that everybody uses js/console.log
though, and I realize that it does work
definitely worth mentioning, especially in #beginners. Thanks!
(js/console.log "hello")
org.mozilla.javascript.EcmaError: ReferenceError: "console" is not defined. (rhino.clj#41)
That's enough to clarify the problem, I think
I don't think you need to
Try one more thing for me: (js/print "Hello, world")
(js/print "Hello, world")
org.mozilla.javascript.EcmaError: ReferenceError: "print" is not defined. (rhino.clj#41)
Hmm, I got that from the docs for rhino shell, but I'm guessing that's a separate product maybe?
are those things rhino defines though?
:thumbsup:
maybe this could help? https://lambdaisland.com/guides/clojure-repls/clojurescript-repls
$ rlwrap lumo -d
Lumo 1.2.0
ClojureScript 1.9.482
Docs: (doc function-name-here)
Exit: Control+D or :cljs/quit or exit
+cljs.user=> (.log js/console "HELLO")
HELLO
nil
@gganley also if you use the new "clj" script, it's straightforward to launch a node repl from that
more info in #tools-deps
fair enough
yup - I like to occasionally glance at how much effort a supposed "productivity tool" extracts as a tax, but as long as you are clear about your decision that's cool 😄
for myself, I discovered that a simpler editor with a lot less tooling was more productive, compared to something that nerd sniped me with cool features I could try to implement or forced me to spend hours fixing configs or library mismatches
but that's a personal choice all the way
But yeah I’ll shift this over to clojurescript since this is quickly getting away from beginner stuff
you can use monroe.el with emacs - I specifically didn't say emacs was the problem - there's more than one kind of tooling available there
(monroe uses nrepl but is much less complex - there's also inferior-clojure which talks directly to any clojure repl)
It’s safe to say though that cider is the de facto way to edit Clojure(Script) code on emacs?
right, just saying there are also simpler options
I am running this query (def get-card-account-emp-link "SELECT * FROM employee_card_account WHERE card_account_id = ?")
with this command (j/query (@db-conn/db-connections (keyword db-name)) [queries/get-card-account-emp-link card-account-id] {:result-set-fn first})
This works, but I get all of the columns in that table which has a lot that I don’t necessarily need. How would I reduce the map I get back from the query to a specific set of columns? One approach would be to only select those columns in the query’s select statement, the other would be to manipulate the map / object after I retrieve it. I can change the select statement, but I’m not sure how to manipulates objects / maps in clojure, which I’m assuming is just as important in clojure as it is in java.
(select-keys <some-map> [<keyword to keep> <other keyword to keep> ..])
should do the trick
it seems a bit odd to SELECT *
and throw away fields afterward
is it that hard to construct a list of fields you want?