Fork me on GitHub

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).


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?


In other words, even though the order is undefined, it should be consistent.


Yeah, I think keys has the same order, just like vals... checking...


oh, ok, but not necessarily alphabetical


Yeah, take a look at the docstring for keys


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.


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.


i doubt browsers allow https xhr requests to be insecure


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 🙂


it’ll produce 21 surprises, if memory serves 😛