Fork me on GitHub
#beginners
<
2018-02-23
>
andy.fingerhut07:02:24

Quiet Thursday evening here in the Western hemisphere, it seems.

kamalnrf12:02:58

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

delaguardo13:02:07

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

josh_tackett14:02:23

anyone know a clojure.string/join that maintains order?

manutter5115:02:24

Do you have some code where clojure.string/join does not maintain order?

josh_tackett15:02:41

`(clojure.string/join "," (mapv name (keys (first row-maps))))`

josh_tackett15:02:03

maybe its the `(keys ...)` that is ruining the order? @manutter51

manutter5115:02:24

It's naturally unordered, due to the nature of maps

mfikes15:02:37

Hmm. `keys` and `seq` / `first` / `next` should all maintain the same order, even if it is based on hashes

manutter5115:02:04

`keys` is supposed to be ordered?

mfikes15:02:18

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

mfikes15:02:37

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

manutter5115:02:41

oh, ok, but not necessarily alphabetical

mfikes15:02:53

Yeah, take a look at the docstring for `keys`

mfikes15:02:30

Right, if you want alphabetical, you could do other things, like throw a call to `sort` in there, or start with a sorted map

fmind15:02:41

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}))))
``````

mfikes15:02:17

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

joelsanchez15:02:52

`(contains? (set (keys (get-thread-bindings))) #'*1)` @mfikes @fmind

joelsanchez16:02:25

in the REPL, `*1` is a dynamic var containing the latest result

joelsanchez16:02:30

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

delaguardo16:02:19

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`

DanO16:02:06

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.

DanO18:02:38

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

noisesmith18:02:27

it's not super hard to use XMLHttpRequest directly, if cljs-http comes up short - @ghadi good point

Elena23:02:51

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?

seancorfield23:02:27

@elena.caraba To get started, probably easiest to spec that argument as `ifn?`.

Elena23:02:09

@seancorfield Thank you! I'm going to try that. I didn't know about it.

seancorfield23:02:54

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 🙂

justinlee23:02:38

it’ll produce 21 surprises, if memory serves 😛