Fork me on GitHub
#clojure
<
2017-03-03
>
mike70657400:03:11

I forgot that I could just use predicates

mike70657400:03:44

And I was trying to think of a way of doing it with the provided functions

isaac06:03:31

Why not implements rseq in reverse? eg:

(defn reverse [xs]
  (if (instance? clojure.lang.Reversible xs)
    (.rseq xs)
    (reduce conj () xs)))

qqq06:03:11

I want '+ as a multi method. I can not have '+ as a multi method. The next best thing is to use unicode. Anyone have nice unicode bindings to clojure for math funtions?

joshjones06:03:41

@isaac can you state your question in a different way? not sure what you're asking.

isaac06:03:11

I mean why not implements rseq in reverse?

wei08:03:26

what’s a good way to select all the content between h3 tags? (using enlive or otherwise) sample source: https://docs.google.com/document/d/1v7uDPHlxmDkqjmmVfgoHGnP4jCtXjPIqPHb860kKrso/export?format=html

cgrand08:03:11

@wei

(->
  "<section><h3>a</h3><p>p1<p>p2<p>p3
   <h3>b</h3><p>p4<p>p5<p>p6
   <h3>c</h3><p>p7<p>p8<p>p9</section>"
  e/html-snippet
  (e/select {[:h3] [#{(e/right :h3) e/last-child}]}))

(({:tag :h3,
   :attrs nil,
   :content ("a")}
  {:tag :p,
   :attrs nil,
   :content ("p1")}
  {:tag :p,
   :attrs nil,
   :content ("p2")}
  {:tag :p,
   :attrs nil,
   :content ("p3\n   ")})
 ({:tag :h3,
   :attrs nil,
   :content ("b")}
  {:tag :p,
   :attrs nil,
   :content ("p4")}
  {:tag :p,
   :attrs nil,
   :content ("p5")}
  {:tag :p,
   :attrs nil,
   :content ("p6\n   ")})
 ({:tag :h3,
   :attrs nil,
   :content ("c")}
  {:tag :p,
   :attrs nil,
   :content ("p7")}
  {:tag :p,
   :attrs nil,
   :content ("p8")}
  {:tag :p,
   :attrs nil,
   :content ("p9")}))

sveri12:03:35

How can I get colored output for tests?

sveri12:03:49

I already tried the humane testoutput plugin, but it does not seem to work

sveri12:03:52

I am on ubuntu, btw

martinklepsch12:03:25

When using nippy is it “by design” that once I redef a record or restart a the JVM the thaw process will yield a different record instance than the one I defined?

martinklepsch13:03:14

(defrecord Thing [a b])
(def x (nippy/freeze (->Thing 1 2)))
(defrecord Thing [a b])
(instance? Thing (nippy/thaw x)) ;=> false

moxaj13:03:39

@martinklepsch

(defrecord Foo [])
(def foo (Foo.))
(defrecord Foo [])
(instance? Foo foo) ;; => false

martinklepsch13:03:32

@moxaj right that makes sense, I just assumed nippy would “retrofit” to existing class/record definitions where applicable

moxaj13:03:45

@martinklepsch I'm not sure if there's a way for nippy to know about the new Foo class

martinklepsch13:03:48

Weirdly though even this returns false:

(defrecord Thing [a b])
  (instance? Thing (nippy/thaw (nippy/freeze (->Thing 1 2)))) ;=> false

martinklepsch13:03:11

hm, seems this is caused by my REPL state

b0613:03:14

(defmacro is-not-thrown? [e expr]
  `(is (not ('thrown? ~e ~expr))))

b0613:03:57

but every time it seems the macro does not work when an expression does not throw an exception

moxaj13:03:08

@b06 why is thrown? quoted there?

residentsummer13:03:22

maybe I’m wrong, but is is not needed

b0613:03:34

@moxaj dunno really, just followed the blog post

b0613:03:39

I'll try without

moxaj13:03:23

@b06 nah it's necessary, it's explained in the article, some magic

b0613:03:11

@residentsummer it works. thanks!

residentsummer13:03:26

well, it may work not as expected...

residentsummer13:03:59

because of now we’re missing the is logic completely

b0613:03:48

@residentsummer indeed. it doesn't work when an exception is actually thrown

b0613:03:29

@moxaj I tried removing it but it's not possible

moxaj13:03:08

@b06 hmm.. checking the sources, this might not be possible, because the multimethod dispatches on the first symbol in the expression after is

moxaj13:03:35

so maybe you could register a custom not-thrown? multimethod

residentsummer13:03:44

just checked the source as well

moxaj13:03:20

(why'd you design an API like this ..)

residentsummer13:03:53

@moxaj I don’t get how the solution from the article supposed to work

joshjones14:03:57

@b06 @moxaj @residentsummer Look at the source for thrown? that is linked to in the article. Just reverse :pass and :fail, put this in your code::

(defmethod assert-expr 'not-thrown? [msg form]
  (let [klass (second form)
        body (nthnext form 2)]
    `(try ~@body
          (do-report {:type :pass, :message ~msg,
                      :expected '~form, :actual nil})
          (catch ~klass e#
            (do-report {:type :fail, :message ~msg,
                        :expected '~form, :actual e#})
            e#))))

joshjones14:03:00

(deftest thrown-tests

  (testing "should throw an exception"
    (is (thrown? Exception (/ 1 0))))

  (testing "should not throw an exception"
    (is (not-thrown? Exception (/ 1 1))))
  )

Ran 1 tests containing 2 assertions.
0 failures, 0 errors.

Lambda/Sierra14:03:50

The clojure.test/is macro is baroque, not a good example to follow. (citation: I wrote it.) The good news is that all you need to do to integrate with clojure.test's output reporting is call do-report with one of those maps. You don't even need to use is or implement assert-expr.

jeff.terrell14:03:27

@stuartsierra - Do you have a recommendation for what to use for testing, if not clojure.test/is?

Lambda/Sierra14:03:17

I didn't say do not use is.

Lambda/Sierra14:03:55

Use is where it is appropriate. If you want to add your own custom testing predicates, with custom reporting, write a function or macro that calls clojure.test/do-report

dominicm15:03:35

So much pain caused by not using the report stuff

jeff.terrell15:03:13

@stuartsierra - Great, because I'm still using is all the time. :-)

seancorfield16:03:19

Expectations now supports all the clojure.test tooling if you want a different style of tests...

miikka17:03:31

Heh, every channel I look at has a clojure.test/report discussion

johnnyillinois20:03:14

Can someone provide me guidance about adding a DOS filter to a ring project using the jetty adapter? Has anyone done this? Can you send me a link to your blog post or maybe a DM? The DOS filter I am currently vetting is: https://wiki.eclipse.org/Jetty/Reference/DoSFilter

hiredman20:03:59

so for a jetty filter, you would likely attach that at the level of jetty, before ring has anything to do with it

hiredman20:03:12

filters, I think, are a java servlet thing, and would sit under the layer that is mapping between servlets and ring (which for jetty would be the servlet adapter)

hiredman20:03:13

so any jetty docs should apply just fine (not a ring specific issue)

zerocooljs22:03:30

Hi please can you help me?? I create this spec (s/def :channel #(re-matches #"(?i)KUSHKIPAGOS" %)) and when I execute (s/gen model-keyword) to generate a data of the spec I’m receiving the error Unable to construct gen at: [:channel] for: :channel {:clojure.spec/path [:channel]

zerocooljs22:03:32

I saw the overrides parameter on the gen function but I don’t understand how to use it

mike70657422:03:01

I think if you use (s/and string? #re-matches ...) it may work

mike70657422:03:08

s/and will use the first predicate to select the generator

plins22:03:41

hello folks, is it possible while using clojure.match pattern match against empty list? ()

zerocooljs22:03:34

@mike706574 now I’m getting the error Couldn't satisfy such-that predicate after 100 tries.

dpsutton22:03:36

@plins are you getting syntax errors?

dpsutton23:03:25

seems like a bug

tanzoniteblack23:03:06

@zerocooljs isn't #(re-matches #"(?i)KUSHKIPAGOS" %) only going to match the string "KUSHKIPAGOS" (with varying case); it doesn't seem terribly surprising that the random string generator that spec is using isn't likely to generate that particular combination of characters within 100 tries with no other information than, "it's a string"

alanspringfield23:03:05

Hello guys, are there any open-source Clojure(script) projects out there suitable for a newbie to open-source but familiar with Clojure(script) to contribute to?

zerocooljs23:03:58

@tanzoniteblack yes is only to check KUSHKIPAGOS with case insensitive

tanzoniteblack23:03:29

@zerocooljs you might benefit from that thing that @gfredericks just sent me then

gfredericks23:03:43

although come to think of it it doesn't support (?i)

gfredericks23:03:58

so you'd have to do something dumb like "[kK][uU]..." 😕

shaun-mahood23:03:14

@alanspringfield: Take a look at http://open-source.braveclojure.com/ - there's a "beginner friendly" checkbox that should get you some good options.