Fork me on GitHub
#clojure
<
2015-11-10
>
darwin00:11:36

I’m not sure how to let my macro know the user’s intended target version, I need something like a “global variable” for macro and I don’t want the user to pass it into every function call

bronsa00:11:40

@domkm: the nullary versions of and and or are driven by how they are often used in macroexpansion

bronsa00:11:12

nil has no effect on an or expression, true has no effect on an and

bronsa00:11:25

IOW just as 0 is the identity for + and 1 is the identity for *, nil is the identity for or and true for and

domkm00:11:44

@bronsa: Ah, makes sense. Thanks.

domkm00:11:42

@bronsa: So or could have returned false instead of nil?

malcolmsparks00:11:04

Is incoerceably a word?

mocker00:11:21

What libraries should I look at to build a client/server where multiple clients will be displaying a page, and then from a ‘control’ page can tell one of the clients to display a different page? Based off searching I’m thinking maybe sente for communication between client and server?

sashton00:11:30

Any ideas on a better way to put a list of objects into a map by a given key?

(let [items [{:id 1 :color :red}
             {:id 2 :color :blue}]]
  (into {} (map #(vector (:id %) %) items)))

=> {1 {:id 1, :color :red}, 2 {:id 2, :color :blue}}
It works, but I just wonder if there's another way.

xeqi01:11:32

@sashton: (zipmap (map :id items) items)

cfleming02:11:00

Does anyone know of a Clojure macro that does really good syntax error checking?

cfleming02:11:16

Doesn’t have to be core, macros from libs are fine

Alex Miller (Clojure team)02:11:56

Did you see chouser and claggetts talk on this at c west a couple years ago?

cfleming02:11:43

@alexmiller: Yeah, I’ve watched that multiple times simple_smile

cfleming02:11:59

They mostly have examples of macros with bad syntax checking though

Alex Miller (Clojure team)02:11:38

what about the prismatic stuff?

Alex Miller (Clojure team)02:11:44

or are they too complicated?

cfleming02:11:44

(of which I have plenty)

cfleming02:11:56

No, complicated is fine - I’ll take a look, thanks.

Alex Miller (Clojure team)02:11:00

probably a couple others in test.check

aenachronism11:11:35

Quick syntax question … I’ve been bashing my head on destructuring function args, I’m currently using : (fn [arg1 arg2] (let [[_ v] arg2 … but I would ideally like to get rid of that let … but I just can’t seem to get it right 😢

dm311:11:34

(fn [arg1 [_ v]] ...) ?

aenachronism11:11:13

@dm3 Brilliant! Does the trick … man that’s nice 😄

martinklepsch13:11:26

Hey! I’m using collection-check to test a custom type but get failing tests like this one:

FAIL in (collection-check) (collection_check.clj:176)
set-like
expected: #{}
  actual: #{}
    diff: - #{}
          + #{}
What do I do with this? How can two empty sets be not equal?

dm313:11:12

if their equals says they're not

dnolen13:11:27

@martinklepsch: you need to implement equals hashCode and IEquiv if I recall correctly

martinklepsch13:11:46

@dnolen: I have IHashEq, I think IEquiv is not a thing in Clojure?

martinklepsch13:11:02

@dm3: (.equals #{} #{}) and (= #{} #{}) are true though. Are there things that can affect .equals that aren’t visible in a sets printed representation?

martinklepsch13:11:48

Also the strange thing is that my custom type has a different string representation than #{} so the one shown in the test output can’t be mine (?)

dnolen13:11:39

@martinklepsch: ah yeah been a while, equals

dnolen13:11:16

@martinklepsch: doesn’t collection check test your stuff against the standard collections?

martinklepsch13:11:02

@dnolen: yes, thats how I understand it..

dm313:11:04

@martinklepsch: what does (.equals (make-your-set) #{}) do?

dnolen13:11:20

@martinklepsch: so equality is a binary op and the order may be flipped, you need to account for both cases

dnolen13:11:29

you’re out of luck if you don’t control the other type

dnolen13:11:45

however Clojure’s implementations should be checking for the interface not concrete types

martinklepsch13:11:09

@dm3: it returns false. and I just noticed that for some reason my print-method multimethod extension isn’t being ran, thus resulting in the same string rep

martinklepsch13:11:56

Let me figure out that, probably that will clear most of the confusion and then I can tackle proper equality

martinklepsch14:11:39

If I require a namespace it’s defmethod calls should get evaluated right?

colin.yates14:11:28

but note there are some funnies around an existing REPL picking up changes to already defined protocols and such like...

martinklepsch14:11:33

@colin.yates: thanks. not worried about protocols atm simple_smile

colin.yates14:11:13

I have also experienced an existing REPL not picking up changes to a defmethod is what I meant (sorry - mind elsewhere). Does restarting the REPL help?

martinklepsch14:11:02

@colin.yates: I’m running tests from clean slate so everything is fresh every time.

colin.yates14:11:47

not sure what the problem is then, but yes, requiring a namespace ‘activates’ the defmethods in that namespace.

colin.yates14:11:16

grasping at straws - I don’t know what effect a restrictive require would have, where you only pull in some vars….

martinklepsch14:11:18

@colin.yates: I think I have a bunch of problems here and will need to figure out some of them before I can ask any more useful questions simple_smile

colin.yates14:11:05

he he - I am well aware of that phenomenon simple_smile

Lambda/Sierra14:11:23

You can't require just "part" of a namespace. Regardless of how many symbols you :refer, the whole file is loaded.

colin.yates15:11:12

thanks @stuartsierra - so the straw disintegrates simple_smile

martinklepsch15:11:13

@dnolen: that order flipping comment was helpful thanks. Turns out I didn’t implement java.util.Set and that’s checked when .equals is called on Clojure sets

wordsarewind15:11:10

is there a flip function in the clojure standard library, and, if not, why? (by "flip function" I mean a function which essentially reverses the application of the arguments applied to some arbitrary function)

wordsarewind15:11:57

I've been using anonymous functions to wrap around functions whose order of application is not what I want, yet I'm wondering if there is a more idiomatic way of doing this... such as the flip function in Haskell

swizzard15:11:04

@wordsarewind: so you want something like (flip f c b a) -> (f a b c)?

wordsarewind15:11:06

I wrote a quick function that does just that, though I wasn't sure if it wasn't idiomatic

roberto15:11:40

should be easy to write your own:

(defn flip [f] (fn [& args] (f (reverse args))

roberto15:11:03

well, just thinking out loud, not sure if that will work

roberto15:11:07

but that is the general idea, I think

wordsarewind15:11:32

yet using it in code... would that confused people?

swizzard15:11:36

without claiming to know the hearts and/or minds of rich et al., i suspect the answer to why there isn’t one in the stdlib involves argument destructuring

roberto15:11:53

also, why are you trying to flip the function?

wordsarewind15:11:11

it's really helpful in a lot of places

roberto15:11:16

because some functions can’t be chained with -> or ->> ?

wordsarewind15:11:27

yep, or with composition

roberto15:11:53

if they don’t fit nicely with -> or ->> I always use partial

roberto15:11:09

also, if I’m trying to compose my own functions, and they can’t be chained nicely with the thread macro, I always step back and re-think my strategy. Most of the times leading me to refactor my functions so they do work that way.

wordsarewind15:11:38

though it's usually to deal with library functions

roberto15:11:49

I’m guessing it is the same with Haskell, you think a lot about how the functions will compose and that informs as to the argument order

roberto15:11:02

yeah, with library functions, I use partial

wordsarewind15:11:03

I like the look of as->, though

roberto15:11:15

there are a lot of nice variants of the thread macros

roberto15:11:21

cond-> is pretty clever too

wordsarewind15:11:50

okay, well thanks

Alex Miller (Clojure team)15:11:13

^^ been working on this for a while! let me know if questions

colin.yates16:11:01

this is great @alexmiller and a step in the right direction ‘community’ wise.

Alex Miller (Clojure team)17:11:38

We would really appreciate it if you could try it out on your internal project or libraries and report any issues you find! This is a candidate for release if no problems are found.

ikitommi19:11:28

Hi. We just released first non-snapshot version of Kekkonen, a data-driven lib for building remote (CQRS) apis. More info at https://groups.google.com/forum/#!topic/clojure/jLx2igfIbHo

ghadi19:11:02

Just released an initial Clojure API client for PokitDok. We are a set of backend APIs for health transactions. Think Parse or AWS but for healthcare https://github.com/pokitdok/pokitdok-clojure

ghadi19:11:56

I know "Client APIs" aren't super idiomatic in clojure-land, so it's oriented around handling oauth negotiation and has a few extension points

timvisher20:11:37

If you know anyone in the Philly area that might be interested in a Clojurebridge event, send them a link! simple_smile http://www.meetup.com/Clojadelphia/

bradford23:11:14

Whoa, https://github.com/ctford/traversy is magic. Solves a lot of questions I had on navigating maps and applying fns to portions thereof. 👏:skin-tone-2: to @rbxbx

bradford23:11:40

Makes it really easy to me to build a DAG with loom and then annotate the graph with info from a bunch of config files, etc

bradford23:11:45

no moar loops

bradford23:11:52

This is so generally useful, I wish more clojure intro tutorials mentioned it

nooga23:11:39

looks like pr-str truncates its output

nooga23:11:45

I tried to spit a huge list of vectors into a file but every way I try either truncates the data or produces something like clojure.lang.LazySeq@46cdfe12

seancorfield23:11:11

Sounds like you need to force realization of the lazy sequence with doall?

seancorfield23:11:45

Or perhaps use doseq and write multiple pieces...

nooga23:11:57

(-> l doall pr-str) and just (doall l) don’t produce desired result