This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-28
Channels
- # announcements (5)
- # babashka (7)
- # beginners (101)
- # biff (9)
- # calva (46)
- # cider (6)
- # clj-yaml (2)
- # cljsrn (13)
- # clojure (11)
- # clojure-europe (43)
- # clojure-nl (13)
- # clojure-norway (22)
- # clojurescript (20)
- # conjure (1)
- # cursive (7)
- # data-science (2)
- # datomic (26)
- # emacs (38)
- # graphql (27)
- # gratitude (5)
- # hoplon (8)
- # hugsql (22)
- # humbleui (2)
- # hyperfiddle (6)
- # introduce-yourself (8)
- # joyride (3)
- # lsp (79)
- # malli (6)
- # nbb (67)
- # portal (16)
- # rdf (27)
- # reagent (42)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (36)
- # test-check (17)
- # tools-deps (1)
- # xtdb (15)
I would like to build a cross-platform application (desktop, android, and ios) using clojure and clojurescript and I was wondering if anyone knows of any useful starting points like templates or existing repos that I could look at.
Closest I found a few months ago was React Native + cljs, like this example app: https://github.com/JohnDoneth/react-native-web-cljs
This could help too: https://cljsrn.org/
Has anyone tried regular expression which matches both url http://abc.def.com https://xyz.def.net
Do you mean a regex that matches only one of those two URLs, and no other strings?
Or some more general pattern you have in mind?
Can you describe the general pattern you wish to match?
And the short answer to your question is "yes", but I suspect you would like to see the regexes people have used š
There are some regexes people suggest for this purpose in this StackOverflow Q&A, but they might require some modification in syntax to be usable in Clojure/JVM or ClojureScript, because when you get fancy enough sometimes regex syntaxes differ a bit between programming languages that have them: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
So exactly two dots after the // ?
Or any number of dots?
user=> (re-matches #"^(http|https):\/\/(.*)$" "")
["" "http" "foo"]
user=> (re-matches #"^(http|https):\/\/(.*)$" "")
["" "https" "my.company"]
Can simplify the regex slightly by getting rid of those backslashes -- habit from me learning regex on Perl many years ago, where that was needed:
user=> (re-matches #"^(http|https)://(.*)$" "")
["" "https" "my.company"]
user=> (re-matches #"^(http|https)://(.*)$" "")
["" "http" "foo"]
That will match many strings that contain things after the // that one would not consider a good URL
This would be one way. The backslash before the dot that has a backslash before it, is because . is interpreted specially inside a regex as "match any one character", unless you put a backslash before it, in which case it means "match only a dot":
user=> (re-matches #"^(http|https)://(.+)\.(.+)$" "")
nil
user=> (re-matches #"^(http|https)://(.+)\.(.+)$" "")
["" "http" "my" "company"]
If you want any number of dots, but no consecutive dots, it starts getting a bit longer of a regex to get it right.
I hope this isn't a poor usage of multimethods but I'm trying to learn them doing some image mods and I can't get this right...
(defmulti transform class)
(defmethod transform Integer [b] (invert-bits b))
(defmethod transform Color [b] (grayscale b))
I keep getting an IllegalArgumentException
when I pass in e.g. (int 3)
should be fine, maybe post more code or (pst *e)
or maybe be aware that defmulti
has defonce
semantics if you are trying to redefine it at the repl
(defn invert-bits [i]
(bit-and-not 0xff i))
(defn grayscale [cs]
(let [r (.getRed cs)
g (.getGreen cs)
b (.getBlue cs)]
(/ (reduce + [r g b]) 3)))
This is all my dispatch fns dothe pst
would tell you where the exception is coming from
clojure.lang.MultiFn/getFn (MultiFn.java:156)
clojure.lang.MultiFn/invoke (MultiFn.java:229)
day-four/eval7811 (NO_SOURCE_FILE:26)
clojure.lang.Compiler/eval (Compiler.java:7194)
clojure.core/eval (core.clj:3215)
clojure.core/eval (core.clj:3211)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:87)
clojure.core/apply (core.clj:667)
clojure.core/with-bindings* (core.clj:1990)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:87)
clojure.main/repl (main.clj:437)
clojure.main/repl (main.clj:458)
clojure.main/repl (main.clj:368)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:84)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:56)
nrepl.middleware.interruptible-eval/interruptible-eval (interruptible_eval.clj:152)
nrepl.middleware.session/session-exec (session.clj:218)
nrepl.middleware.session/session-exec (session.clj:217)
java.lang.Thread/run (Thread.java:833)
This doesn't seem to point to anything except where I evaluated (transform (int 3))
the code you posted should be fine, I'm wondering if you redefined transform
at the repl (and that redefinition didn't actually take place)
user=> (defmulti transform class)
#'user/transform
user=> (defmethod transform Integer [b] (println "got int" b))
#object[clojure.lang.MultiFn 0x20095ab4 "clojure.lang.MultiFn@20095ab4"]
user=> (transform (int 3))
got int 3
nil
works fine for exampleAh yes, that was it. Thanks Alex!
(map (fn [times n]
(sort (take times (distinct (repeatedly #(rand-int n))))))
[[10 20] [2 5]])
Hi everyone, I am experimenting with map
and fn
, however this example does not work and I could not figure out why... I think something like this in CL would work...
This is the full function I want to write:
(defn foo []
(map inc
(concat (map (apply (fn [times n]
(sort (take times (distinct (repeatedly #(rand-int n)))))))
[5 33] [2 10]))))
(map (fn [[times n]]
(sort (take times (distinct (repeatedly #(rand-int n))))))
[[10 20] [2 5]])
this indentation should make it clearer @U0306EUQCP6 ^@U050ECB92 I just updated the code. It now goes into infinite loop
@U050ECB92 yes it now works, thank you. So the problem is that I should use [[ā¦]] when there are multiple arguments?
(fn [[times n]]
... )
is sugar for
(fn [m]
(let [times (m 0)
n (m 1)]
...))
https://clojure.org/guides/destructuringI got an xml which looks like this:
<Rates type="dictionary">
<Info type="dictionary">
<Time type="dateteime">Fri, 28 Oct 2022 16:59:23 GMT</Time>
</Info>
<EURUSD type="dictionary">
<Spot type="dictionary">
<Pair type="string">EURUSD</Pair>
<Bid type="double">0.993</Bid>
<Ask type="double">0.994</Ask>
</Spot>
</EURUSD>
</Rates>
What's a standard way to work with such an xml in Clojure? Suppose I want to extract the time, pair, bid and ask values from this.
I see a lot of disparate ways (zippers, walkers, specter) etc mentioned in different places.
Let me rephrase, what would be the easiest way to do this and what would be a reusable way?
For example, I have a lot of xmls like these with different structures and I can think of a use case like this:
(defn get-xml-vals [xml paths] ...)
(get-xml-vals above-xml ["./Rates/Info/Time" "./EURUSD/Spot/Pair" "./EURUSD/Spot/Bid" "./EURUSD/Spot/Ask"])
=> [#inst "2022-10-28T16:59:23.000-00.00" "EURUSD" 0.993 0.994]
Which could make me save time. Or is that even possible?of course - just need to compose some things together
there are Clojure libs like org.clojure/data.xml for parsing the xml into Clojure maps
things like org.clojure/data.zip for traversing those trees
but you might find it more efficient to use some of the many Java XML libraries and things like XPath to extract values too if you are primarily extracting data of known shape
this is a reasonable example page of doing this with the relevant java apis - https://www.baeldung.com/java-xpath (which are very complete, but also quite tedious)
it's not a bad idea to first just try to make interop work, then think about how you'd want to describe this op in Clojure and then build the thing in the middle. depending how reusable you want that to be will affect how much effort you put into the middle
Iām having a problem fetching a dependency
Error building classpath. Could not find artifact bouncycastle:bctsp-jdk14:jar:138 in central ((https://repo1.maven.org/maven2/https://repo1.maven.org/maven2/))
in general "moving to another path" means the old versions stay where they are, and new versions have a different maven coordinate, so while possible, it is unlikely that is the source of your error
Iām using a correct mvn repo for sure
if you look at maven central https://repo1.maven.org/maven2/bouncycastle/bctsp-jdk14/138/ the artifact is there
it is a correct maven repo, but the name it shows "central" is usual used to refer to the central maven big maven repo at http://maven.org
it seems like in your setup, for whatever reason, central is pointing somewhere else, and that somewhere else may be a valid maven repo, for whatever reason is doesn't have the artifact you are looking for
I can point to more than 1 repo?
Iāve add to :mvn/repository
how to do that will depend on whatever tools you are using, so you should consult the documentation (deps.edn, lein, maven, etc)
deps.edn
it has a ticket for same dependency that I have
it is possible you are hitting that bug, but I would first try without whatever you are doing to overwrite central
Error building classpath. Could not find artifact bouncycastle:bctsp-jdk14:jar:138 in central (https://repo1.maven.org/maven2/)
you may need to binary search your dependicies then, comment out half, see if starting a repl errors or not
Is there any better way instead binary search?
that will get you to the one that is pulling that in, and you can add an exclusion, and then include the relocated coordinates in your deps
depending on your setup, if you just have a deps.edn with some deps in it, then the binary search should be the fastest simplest way
if you are are doing stuff with a lot of aliases, or have a lot of stuff in ~/.clojure/deps.edn then it might be tricky
I have a lot of deps
this will be tricky
a more verbose output for deps.edn would be cool
sure, but if they are all specified in one place, you just comment the top half, see if a repl will start
if that works, you know the failing is in the top half, so you comment out the bottom half, and the top quarter and it again
I think it's highly likely that the problem here is the bouncycastle relocation
The url up top for Maven central is a valid Maven repo so I don't think that's an issue
one hack that might help is actually to generate a pom clj -Spom
then use Maven mvn dependency:tree
found by binary search
took me a lot \
Iāve seen that this artifact has moved to other path
Iām using clj
how can I find the dependency that depends on bouncycastle:bctsp-jdk14:jar:138
if my clj -Stree gives me error ?
Quick question, why there is no nil punning for the function name
?
Nil punning (as a language feature) generally applies to sequences. The cases where it applies to strings mostly derives from strings being seqable. It is usually pretty straightforward to create additional ad-hoc nil-punning, by wrapping something up in a nil check.
(defn name-pun
"name, but with nil punning"
[x]
(when-not (nil? x) (name x)))
(name-pun :foo) ;; "foo"
(name-pun nil) ;; nil
You could even create a fn:
(defn pun-it [f]
(fn [x]
(when-not (nil? x) (f x)))
(def name-pun (pun-it name))
This is probs not āgeneralā enough, since it doesnāt deal with fns which take more than one argument. Have a look at fnil
for some additional inspiration.Nice, thank you!