This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-26
Channels
- # aleph (4)
- # announcements (3)
- # babashka (31)
- # beginners (74)
- # bitcoin (7)
- # calva (11)
- # cider (17)
- # clj-kondo (5)
- # clojars (11)
- # clojure (81)
- # clojure-australia (3)
- # clojure-dev (73)
- # clojure-europe (136)
- # clojure-nl (5)
- # clojure-spec (10)
- # clojure-uk (41)
- # clojurescript (30)
- # core-async (1)
- # cursive (19)
- # data-oriented-programming (4)
- # datascript (5)
- # datomic (6)
- # docker (6)
- # emacs (1)
- # figwheel-main (1)
- # fulcro (6)
- # jobs (1)
- # jobs-discuss (17)
- # lsp (23)
- # malli (6)
- # off-topic (35)
- # pathom (2)
- # re-frame (56)
- # reitit (2)
- # rewrite-clj (3)
- # shadow-cljs (10)
- # spacemacs (6)
- # sql (11)
- # vim (16)
- # xtdb (3)
Hi, I'm reading https://github.com/linpengcheng/PurefunctionPipelineDataflow/blob/master/doc/relational_model_on_hashmap.md and I wonder what this "empty" commas at the end mean
(defn join [db main_table join_table join_col]
(let [f #(let [x (-> db main_table %2)]
(->> x
join_col
(get (db join_table) ,)
(merge x ,)
(assoc %1 %2 ,)))]
(->> db
main_table
keys
(reduce f {} ,)
doall)))
any hints ? never saw anything like this ...So they don't mean anything to clojure, but some people do that kind of thing to mark where threading macros will insert their arguments
hi i tried to understand this https://clojuredocs.org/clojure.core/read-line in my doom-emacs, it'll prompt an input, but once i input it in my repl, it stuck, it doesn't return like that. how to do that in emacs?
(do (print "What's your name? ")
(flush)
(read-line))
What's your name? Clojure
"Clojure"
i have to ctrl+c twice and result in error
Execution error (InterruptedException) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject/await (AbstractQueuedSynchronizer.java:1627).
null
emacs uses nrepl so things are a bit more complicated. when you attempt this, you'll notice in the bottom of your emacs window a prompt that looks like this:
been looking for an answer since about 3 wks ago, now it comes to light. I'm so stupid
it makes sense to accept repl input from the repl. its kind of a quirk that it works this way. and the input request is tiny and out of site
couldn't be more agree than this
@U11EL3P9U thank you so much for helping me. https://github.com/dharrigan/google-apis-example/tree/master/src/dharrigan it's because of i couldn't operate the emacs that well, but I got the concept of oauth2 because of you. still it's really simple, but I just found the answer today omg... lol :rolling_on_the_floor_laughing:.. again, thanks a lot!!
emacs is wanting you to type there to send the input rather than in the repl buffer
this can also be accomplished with a small amount of java interop, https://stackoverflow.com/questions/39355241/compute-hmac-sha512-with-secret-key-in-java
Hey guys! I just started trying to use incanter to draw some plots, but whenever I do:
(ns main
(:use [incanter core charts stats datasets]))
clj-kondo yells at me for using :use. Is there a succinct way to achieve the same thing using :refer :all?
(p.s. it also underlines all my incanter functions like histogram due to unresolved symbol even though the code works)@ryan.boldi123 clj-kondo yells at you because it has no way of knowing where some of the symbols in your code are coming from and therefore it discourages :use
and :refer :all
for that matter.
As a human I often have the same problem as clj-kondo, that's why I also don't use :use
myself, I find that the code becomes more confusing. Just use :require
+ :as
or :refer
@borkdudeSo would I need to always use fully qualified names whenever I call incanter functions? Something like incanter.core/view ?
@ryan.boldi123 No: (ns main (:require [incanter.core :refer [view]]))
@borkdude So I would need to write 4 require lines, one for core, charts stats and datasets?
yeah, well you don't have to, you can use nested libspecs, but that's another story ;)
@borkdude Thank you very much!
(ns main (:require [incanter [core :refer [view]] [charts :refer [foo]]]))
This works, but this syntax has gone a bit out of fashion in favor of just writing the namespace names in fullThis is very helpful. I don't mind sticking to doing 4 separate requires for the sake of readability.
What discord? I tried googling and found a couple in years-old reddit comments, is there a "recommended" one?
Does seq
(and thereby keys
and vals
) give some guarantee with respect to ordering for maps with identical keys ?
For example
(defn gen []
(->> (for [i (range 1000)]
[i (rand-int 1000)])
(into {})))
does it always hold that
(= (keys (gen)) (keys (gen)))
no, it doesn't hold across different maps @finn.volkel
@ghadi so the guanrantee is not given, but the implementation always yields the same order or the implemenation does not always yield the same order?
If you add equal keys in same order to two maps the implementation today will have same order
If you add same keys in different orders to two maps, their order of seq, keys, and Vals can differ
Is there an appropriate way to 'pull in' functions from different namespaces into a namespace such that the symbols become accessible in that ns from other namespaces? That seems unclear... what I mean is to be able to do something like this:
(ns svg-clj.main
(:require [clojure.string :as st]
[svg-clj.utils :as utils]
[svg-clj.specs :as specs]
[svg-clj.transforms :as transforms :refer [translate rotate scale centroid bounds]]
[svg-clj.path :as path]))
(some-kind-of-pull translate) ;; something to make the symbols accessible, incl. docstring and args
(some-kind-of-pull rotate)
...
Then, a user would use svg-clj as follows:
(ns user.drawing
(:require [svg-clj.main :refer [circle translate rotate]])) ;; user doesn't need to know about svg-clj.transforms
Hmm... tried that and it almost works. I do have the symbols accessible when :requiring main, but I don't see the argslist show up in my editor (my minibuffer in emacs usually shows the args as I type a fn)
@U01LR7M2B7A That's because the metadata is lost on that intern
-- but you can get the metadata from the original var and add it to the new interned var. Something like this: https://github.com/clojure-expectations/clojure-test/blob/develop/src/expectations/clojure/test.cljc#L538-L546
I'm using update
to append the line about "Imported from..." but you could just do (insert *ns* 'translate (with-meta translate (meta #'translate)))
I think. #'
gets the var behind the function translate
and you need that for the metadata.
I was just messing around with meta! Your linked code example gave me the hint I needed. I did not know about 'resolve' and was struggling to attach meta to the var as opposed to the symbol. Thanks for the help!
https://clojurescript.org/reference/repl-options where can I put these ? I want to set a static path to resources/public so when i jack in I can ajax files tried in build.edn but either thats wrong or I am doing something else wrong 😕
is there a better way to write this?
(let [m {:foo "ab" :bar "cd"}
bar (list (:bar m))
foo (list (:foo m))]
(concat bar foo))
=> ("cd" "ab")
Maybe this post is helpful https://blog.mrhaki.com/2021/02/clojure-goodness-destructuring-maps.html?m=1 how to destructuring maps
@UJ5N28CL8 Is there a reason not to just use [(:bar m) (:foo m)]
rather than creating a singleton list for each item and then gluing them back together?
And as sb says, destructuring can make this cleaner:
(let [{:keys [bar foo]} {:foo "ab" :bar "cd"}]
[bar foo])
This form of destructuring is rarely used, unless you want to rename the keys to something else: {bar :bar foo :foo}
, i.e. {one :bar two :foo}
-- so one
is bound to (:bar m)
and two
is bound to (:foo m)
(sometimes that is absolutely necessary, so it's good to know about, as well as the more common :keys
destructuring)
Another good use for juxt
🙂
Hash maps are inherently unordered. You can't rely on the ordering or the reverse ordering.
And I think the assumption is that there are many other keys in there, but @UJ5N28CL8 only wants two of them.