I was looking at s/fdef a bit, and as you say using instrument will essentially eliminate any need for :pre conditions. Orchestra I haven't heard of and that looks nice for the function output validation too, which would certainly help in my case. Thanks for the feedback
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 ...Commas in clojure are whitespace, the reader ignores them
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
I don't much care for it
thanks, I understan now ....
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:
emacs is wanting you to type there to send the input rather than in the repl buffer
@dpsutton I want to thank you from deepest of my soul!
why you're quite welcome 🙂
been looking for an answer since about 3 wks ago, now it comes to light. I'm so stupid
not at all
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
@dharrigan 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!!
You're most welcome 🙂
Keep on 'learning! 🙂
are there clojure libraries for hmac?
perhaps buddy, https://funcool.github.io/buddy-core/latest/02-mac.html ?
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
thanks! I’ll try them out
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]]))
Or: (ns main (:require [incanter.core :as i]))
and then write (i/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.
Oh, I just answered that also in discord
What discord? I tried googling and found a couple in years-old reddit comments, is there a "recommended" one?
It's called Clojurians
Discord doesn't make it easy to find out the server URL
Try this one : <https://discord.gg/UyKyKzwa>
It was on Invite Someone
Thanks!
you're most welcome! 🙂
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
thanks, that makes sense
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
My guess: (intern *ns* 'translate translate)
, etc.
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 😕
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)
@adam.james 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.
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")
I basically want to take two keys from a map and make a list out of the values
juxt
is awesome, and yes the map contains more than 2 keys
Just for the record, juxt
works with any (positive) amount of keywords (or other fns)
Maybe this post is helpful https://blog.mrhaki.com/2021/02/clojure-goodness-destructuring-maps.html?m=1 how to destructuring maps
If I understand good
@david.daigml 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?
(let [m {:foo "ab" :bar "cd"}
{bar :bar foo :foo} m]
(list bar foo))
And as sb says, destructuring can make this cleaner:
(let [{:keys [bar foo]} {:foo "ab" :bar "cd"}]
[bar foo])
yeah
cool, this is much more idiomatic, thanks
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)
in my use case, :keys
destructuring would work, there is no need to rename the keys
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!
user=> ((juxt :bar :foo) {:foo "ab" :bar "cd"})
["cd" "ab"]
Another good use for juxt
🙂