Fork me on GitHub
#clojure
<
2018-08-03
>
puzzler01:08:21

clojure.lang.IHashEq tells you whether the object implements .hasheq(). Is there a single interface that tells you whether the object implements .equiv(other)?

arrdem02:08:54

Are there any good examples of writing test.check generators for data-dependent sequences? I’m trying to figure out how to use test.check to model a finite state machine, and the best thing I’ve got is recursive application of choice of functions of a state to a state with a longer execution history. Writing that out as a reduction is pretty simple and definitely works, but it’s kinda hard to model in a way which integrates with the rose tree AFAIK.

hiredman06:08:07

do you mean generating fsms?

hiredman06:08:37

you mean using a fsm to generate data

arrdem06:08:12

I got this sorted out - I have a system which implements has a pretty simple accumulator FSM, and I want to use test.check to generate a sequence of inputs and a predicted end state so that I can drive the inputs against the live system and show that the final states align.

arrdem06:08:16

I settled on the fmap bit I posted below which worked out perfectly. Write generators for functions of a “trace” [starting-state, request-sequence, ending-state] to another (presumably longer) trace, let test.check pull from generators of such functions to a sequence of transformers, then apply the transformers in order over an initial input state to realize a sequence of requests and produce a final state.

greywolve14:08:30

I used this and ideas from this and the talk referenced in the post to build something similar to what you want

arrdem02:08:14

gen/recursive-gen isn’t really what I want, because there’s a recursive structure to my generator I want to capture.

arrdem03:08:58

I guess one way to do it would be to (gen/fmap (fn [[seed-state xformers]] (reduce #(%2 %1) seed-state xformers)) (gen/tuple (s/gen ::state) (gen/vector (gen/one-of transformers))))

andy.fingerhut03:08:01

@puzzler I looked around the source for a few minutes and could not find an interface that tells you whether an object implements .equiv(other)

puzzler07:08:48

Consider (defrecord T [^long x]) and then (:x (T. 1)). Am I correct that this expression will not return a primitive, and to get a primitive you need (.-x (T. 1)) ?

puzzler07:08:02

Similarly, if I do (assoc (T. 1) :x 2), that 2 is going to get boxed and then immediately unboxed for storage in the defrecord, correct?

👍 4
arrdem07:08:01

For Clojure at least that is correct - invoking the Keyword can only return a boxed value and no attempt is made to inspect the right hand side and determine that the keyword access could be a field access with a primitive type although the keyword as a field getter has some efficient machinery. I believe that your second example/statement is correct.

arrdem07:08:50

But the only way to really know is to no.disassemble it

Petrus Theron08:08:53

Hey guys, I made a tool in Cljs to translate boot-clj and Leiningen :dependencies to the newer deps.edn format: https://theronic.github.io/depsy/ (source on GitHub)

amar10:08:46

Hello, what’s your favourite Clojure query DSL for production?

jaihindhreddy-duplicate11:08:52

^ Are you talking about SQL?

greywolve11:08:19

What are the benefits of using namespaced keywords for applications, practically, assuming you don't care about namespace clashes ?

joelsanchez11:08:26

if the use of a keyword assumes a ns has been required, you can use a namespaced keyword and refer to it with a namespace alias, that way you ensure it's been required

joelsanchez11:08:42

(think about spec, re-frame...)

joelsanchez11:08:31

also, semantics

greywolve11:08:24

Could you elaborate on this?

joelsanchez12:08:23

regarding simply namespaced keywords, it's not the same :product/price than :price, because you have more context

joelsanchez12:08:46

regarding fully qualified namespace keywords, knowing the namespace gives you information on where does the keyword come from and possibly additional documentation

joelsanchez12:08:51

so it has more meaning

greywolve12:08:19

true, but i suppose that begs the question, how often will you receive a map, working with an application, and not know the context anyway (even though it's not explicit in the namespace)

joelsanchez13:08:28

it simply makes things clearer, easier to document and specify, easier to read

joelsanchez13:08:45

but it's not always justified, ofc

mpenet13:08:44

Also the default multimethod hierarchy only supports namespaced keywords/symbols

mpenet13:08:57

Also it can help makes some datastructures simpler (single level map with lots of diff "types" instead of nesting)

acron12:08:59

What's the difference between s/every and s/coll-of ?

acron13:08:18

Unlike 'every', coll-of will exhaustively conform every value. got it

borkdude14:08:02

(t/are [x y]
      (= (let [{:keys [a b]} x] [a b]) y)
    {:a 1 :b 2} [1 2]
    {:a 1 :b 2} [2 2] ;; false
    {:a 3 :b 4} [3 4]
    ) ;; true
eeeh….

john14:08:31

eh, the second binding is clobbering the previous a and b? Maybe renaming the second set of bindings?

borkdude14:08:15

no, it just returns the result of the last test

john14:08:44

I misread the binding

john15:08:09

(t/are [x y]
        (= x y)
      :not :equal         ;; fail
      :not-this :either ;; fail
      [2] [2]
) ;; true

john15:08:21

Returns the result of the last test

john16:08:13

(defmacro all-are
  [argv expr & args]
  (if (or
       (and (empty? argv) (empty? args))
       (and (pos? (count argv))
            (pos? (count args))
            (zero? (mod (count args) (count argv)))))
    (let [c (count argv)]
      `(clojure.core/and 
        ~@(map (fn [a] (clojure.template/apply-template argv `(clojure.test/is ~expr) a)) 
               (partition c args))))
    (throw (IllegalArgumentException. "The number of args doesn't match are's argv."))))

hiredman16:08:42

clojure.test/is and clojure.test/are are like assertions, you shouldn't care about the return value

john16:08:58

naw, that didn't work confused typo

xiongtx17:08:10

Is there a way not to parameterize HoneySQL values? E.g.

(honeysql.format/format
 (-> (h/insert-into :FOO)
     (h/values [{:a 1 :b 2 :c 3}])))
;; => ["INSERT INTO FOO (a, b, c) VALUES (?, ?, ?)" 1 2 3]
But as a single string?

xiongtx17:08:08

☝️ Seems like I can map honeysql.core/inline to all map values

seancorfield19:08:57

@xiongtx There's also an #inline reader literal in HoneySQL: [{:a #h/inline 1 :b #h/inline 2 :c 3}] should result in only 3 becoming a parameter.

hmaurer22:08:07

Hello! Is there a way to tell which procols an object implement? When dumping certain objects in the repl I get things like reify__1987, which isn’t very descriptive

sundarj23:08:25

looks like

=> (parents (class (reify clojure.core.protocols/CollReduce)))
#{clojure.lang.IObj clojure.core.protocols.CollReduce java.lang.Object}
maybe works

hmaurer23:08:14

@U61HA86AG oh yes, that works. Thank you!

hiredman22:08:41

you can ask if an object satisfies a specific protocol using satisfies?

hmaurer22:08:26

So if I see an object described as reify__1987 (or similar), I have no way to figure out what that thing is?

hiredman23:08:00

the protocols implemented don't tell you what it is anyway

andnils23:08:00

So...I converted some local project from lein to deps.edn for fun. One thing that surprised me was when my Project2 had a dependency of type ":local/root" to Project1. Project1 (also using deps.edn) had a dependency to "httpkit". I expected that Project2 would retrieve the transitive dependencies, but no. I had to add "httpkit" as a dependency to Project2 as well. Is this the way it is supposed to work?

andnils23:08:57

...do I always need to add transitive deps to my "deps.edn"?

gfredericks23:08:21

that would surprise me quite a bit

ghadi23:08:24

that sounds like there is a problem with the deps.edn @andnils

emccue23:08:45

Im looking for a fun side project to work on using clojure

emccue23:08:04

if anyone wants or needs a code monkey i am available