This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-23
Channels
- # aleph (8)
- # aws (2)
- # beginners (36)
- # cider (35)
- # cljs-dev (157)
- # cljsjs (3)
- # cljsrn (5)
- # clojure (97)
- # clojure-dev (5)
- # clojure-gamedev (3)
- # clojure-italy (27)
- # clojure-russia (11)
- # clojure-spec (19)
- # clojure-uk (39)
- # clojured (6)
- # clojurescript (87)
- # clojutre (4)
- # community-development (35)
- # cursive (8)
- # datascript (2)
- # datomic (14)
- # dirac (8)
- # duct (3)
- # figwheel (13)
- # fulcro (22)
- # graphql (20)
- # jobs (1)
- # london-clojurians (1)
- # off-topic (55)
- # onyx (3)
- # parinfer (3)
- # protorepl (39)
- # re-frame (3)
- # reagent (26)
- # ring (7)
- # ring-swagger (2)
- # rum (1)
- # shadow-cljs (107)
- # spacemacs (8)
- # test-check (4)
- # unrepl (3)
Howdy.
Quiet Thursday evening here in the Western hemisphere, it seems.
I'm trying to find prime factors for a number. I was able to get what I wanted using map function but when tried to find for number of size billion it was taking forever to compute can someone tell what will be best way to compute large numbers
It is hard to tell without seeing your algorithm)
Right, something about your algorithm. It shouldn’t take “forever” at all, should be nearly instant even for a number like 1 billion.
Pay attention to how you are using map
. Remember map
processes the entire list exhaustively, and that could be way more computation than you actually need. (My implementation doesn’t use map
at all).
@kamalnrf have you consider this solution ? https://stackoverflow.com/questions/9556393/clojure-tail-recursion-with-prime-factors
anyone know a clojure.string/join that maintains order?
Do you have some code where clojure.string/join does not maintain order?
(clojure.string/join "," (mapv name (keys (first row-maps))))
maybe its the (keys ...)
that is ruining the order? @manutter51
It's naturally unordered, due to the nature of maps
Hmm. keys
and seq
/ first
/ next
should all maintain the same order, even if it is based on hashes
keys
is supposed to be ordered?
oh, ok, but not necessarily alphabetical
Right, if you want alphabetical, you could do other things, like throw a call to sort
in there, or start with a sorted map
do you know a way to detect if the program is executing from command-line or from a repl ? At the moment, I have to define a var for that purpose
(defn exit! [code]
(when-not (resolve 'DEV)
(System/exit code)
(throw (ex-info "exit!" {:code code}))))
@fmind That's an interesting question. The only way I can think to do it is to look at (Exception.)
and try to find clojure.main$repl
in the trace. Hrm.
(contains? (set (keys (get-thread-bindings))) #'*1)
@mfikes @fmind
in the REPL, *1
is a dynamic var containing the latest result
which, by the way, is also the responsible of the impossibility of printing the result of (get-thread-bindings)
directly in the REPL - as it contains *1
and *1
contains (get-thread-bindings)
, it generates an StackOverflowException
Also trying to resolve any def from clojure.repl namespace (like doc
, find-doc
or source
) might do the job
(boolean (resolve 'doc)) ;; => true (in repl) and false within lein run
This is a question about cljs-http, specifically, and since I can’t find a channel for that, and because I’m a beginner, I’m posting it here.
Is there a way in cljs-http to send a request to an endpoint that ignores certificate checks? I’m trying to hit a service that currently uses a self-signed cert, as it is still under development. If I use curl
to hit the site, I get a certificate error, but if I use curl -k
it succeeds. I’m hoping there’s a way in cljs-http to emulate that -k
switch. Or if someone has a different suggestion to accomplish this, I’d be open to that also.
https://github.com/dakrone/clj-http search for "insecure"
I have tried including :insecure? true
in the request, but that feature doesn’t seem to be written into cljs-http. It doesn’t appear to change the result. I suppose I could look into using clj-http instead.
it's not super hard to use XMLHttpRequest directly, if cljs-http comes up short - @ghadi good point
I'm new to Clojure and to spec. I have a function that takes as arguments among other things another function. What's the way to do the spec for that function? I attempted string? but of course it's not and it returns the error that #object[...function-name...] fails predicate string?
@elena.caraba To get started, probably easiest to spec that argument as ifn?
.
@seancorfield Thank you! I'm going to try that. I didn't know about it.
You could use fspec
to write a full spec for that function argument, but if you instrument
your function, spec will try to generatively test the function argument, so it'll want to pull in test.check
and exercise the function passed as an argument with randomly generated (conforming) data -- which might produce surprises if you pass a function with side effects 🙂