Fork me on GitHub
#clojure
<
2018-01-31
>
noisesmith00:01:45

oh wait I think I misunderstood your specification

noisesmith00:01:05

you would need to write different code, or refactor each prob given the probabilities already seen

joshmiller00:01:20

Yeah, I’m just looking to return one element from the collection, but that’s still most of the way there for me I think.

noisesmith00:01:22

(and then call first on the result)

noisesmith00:01:14

you might need to carry a "percentage cumulative" term, which gets us into reduce with a reduced value territory

bellis03:01:37

is there a better way to figure out the namespaces used by default in my repl than this?

lagomorph:excl ellisbben$ clj
Clojure 1.9.0
user=> (distinct (map #(get (clojure.string/split (str %) #"['/']") 1) (vals (.getMappings *ns*))))
("clojure.core" nil "clojure.repl" "clojure.pprint" "clojure.java.javadoc")
user=>

Alex Miller (Clojure team)03:01:39

ns-map might do some of that work for you too?

mbjarland09:01:27

a potentially noob question, is there a one-liner to get rid of the double map access in expressions on the form:

(let [x (when (not (blank? (:key m))) (:key m))]
  ...)
ie return value from map only if a predicate returns true for it, otherwise nil

mpenet09:01:58

(when-let [x (-> m :key not-empty))...)

mbjarland09:01:07

: ) @mpenet Nice. Thanks!

mbjarland09:01:38

new one for me, the docstring for not-empty reads If coll is empty, returns nil, else coll…did not make the connection that that would work for strings, guess they are seen as seqs of characters in this context

mpenet09:01:46

it calls seq on the input, might be "garbage in, garbage out" abuse

mpenet09:01:55

(defn not-empty
  "If coll is empty, returns nil, else coll"
  {:added "1.0"
   :static true}
  [coll] (when (seq coll) coll))

manuel11:01:55

hi everybody, been struggling with compojure-api. I want to define two defapi, because I need to wrap the routes with different middlewares. I have the error reported here (and you can see my comment at the end): https://github.com/metosin/compojure-api/issues/206 Anyone using different defapi in their projects? Thanks 🙂

manuel11:01:51

I don't know what request-options and response-options are

manuel11:01:11

where should they be defined?

manuel11:01:44

moreover, how can I wrap different api under the same app (I am referring to the app in the link you posted) with specific middlewares?

ikitommi11:01:08

are you using 1.* or 2.* version of c-api?

ikitommi11:01:28

I think you can just use [ring.middleware.format/wrap-restful-format] then (uses the default options).

manuel11:01:06

thanks, I'll try that and let you know!

ikitommi11:01:15

or the middlware found in the wiki, but without the options (uses defaults).

manuel11:01:05

oh, but wait, I am already wrapping with that wrap-restful-format both the routes. https://github.com/metosin/compojure-api/issues/206#issuecomment-361885758

manuel15:01:55

since I am not getting anywhere with this, do you suggest I give 2.* a try? I understand there is no ring-middleware-format.

qqq11:01:16

https://github.com/cretz/asmble <-- how do I figure out if this library is in maven, and if not, how do I include it as a dependency anyway ?

gklijs11:01:04

I most of the time google for it, but if it’s on github you can get the source and install it to a local repo.

gklijs11:01:17

aparently not, should be something like asmble/asmble:0.1.0 and seems like you need kotlin to build

grzm15:01:55

@qqq there’s a mention of adding http://jitpack.io as a maven repo here: https://jitpack.io/#cretz/asmble/0.1.0. Includes Leiningen coordinates, so likely someone’s been using it

nha16:01:12

Is there a way to store EDN with comments? Or is the only alternative to store is as a string?

hiredman16:01:58

if you want to get technical, edn is a serialization format, it only exists as a string

noisesmith17:01:39

is metadata part of edn officially? if so :doc metadata might make sense

noisesmith17:01:31

oh, metadata no, but comments and form discarding yes

nha17:01:08

Thanks all 🙂

qqq18:01:02

(defn ia-eq [lhs rhs] 
  (let [sl (count lhs)
        sr (count rhs)]
    (and (= sl sr)
         (every? true? (for [i (range sl)]
                         (= (aget lhs i) (aget rhs i)))))))

(ia-eq (int-array [1 2]) (int-array [1 2]))
(ia-eq (int-array [1 2]) (int-array [1 3]))

this function seems awfully verbose; the (every? true? ....) part is especially ugly

qqq18:01:06

Is there a better wa yo write ia-eq ?

Alex Miller (Clojure team)19:01:21

(= (seq lhs) (seq rhs))

qqq20:01:45

(let [co  (ic/visit {:name    "my.dyn.TestClass"
                       :fields  []
                       :methods [{:name "go", :desc [:long :long]
                                  :flags #{:public :static}
                                  :emit [[:lload 0]
                                         [:ldc2 10]
                                         [:ladd]
                                         [:lreturn]]}]})
      obj (ic/new-instance co)] 
  (obj/to 20))
note that go is a static field; how do I call it ?

nha09:02:45

out of curiosity, what is ic here?

qqq10:02:24

insn.core

hiredman20:01:34

that is a method

qqq20:01:44

sorry, static method

qqq20:01:09

if I didn't mark it static, I could just do (.go obj)

bronsa20:01:32

my.dyn.TestClass/go

noisesmith20:01:39

there's also a more decomposed form if you are eg. constructing a call from a macro

:user=> (. java.lang.Character isDigit \a)
false
:user=> (java.lang.Character/isDigit \a)
false

dealy21:01:46

I'm having some trouble with a :dynamic that sometimes doesn't appear to be defined when accessed on threads started with pmap. Is using functions that allow for dynamic binding not a good idea in this case?

schmee21:01:52

dynamic bindings interact poorly with laziness

schmee21:01:45

the binding is only defined in the lexical scope, but due to laziness the actual realization of values can be after you leave the scope

schmee21:01:32

there is (among lots of other great things) a really good explanation of it in The Joy of Clojure

dealy21:01:07

oh, ok well I guess that kinda explains all the weird behavior I'm seeing

dealy21:01:59

cool thanks

carkh23:01:39

the peril of the perils of dynamic scope : dynamic extent is and stay usefull in some cases. The post is good at pointing out some of the perils, but as is often the case that's not an all black or white thing

noisesmith23:01:15

@carkh it's the best response to someone asking why dynamic bindings break in pmap though - that's exactly why

carkh23:01:41

true enough =)

carkh23:01:00

dynamic scope was one of those features that blew my mind when i started with CL

carkh23:01:10

I'll defend it till death !

noisesmith23:01:40

also note the article ends with "dynamic is not always bad here's why it's useful and here's how to use it safely"

carkh23:01:13

yes but in the comments, Stuart is a bit more assertive =/

noisesmith23:01:01

? it's the last section of the article I'm talking about > Safe Dynamic Scope > So dynamic scope is totally evil, right? Not totally. There are situations where dynamic scope can be helpful without causing the cascade of problems I described above.

carkh23:01:18

yes indeed

carkh23:01:57

nice examples too with the json parser and clojure compiler