Fork me on GitHub
#clojure
<
2017-08-12
>
andrea.crotti10:08:00

any suggestion for a good Clojure library for Twillio?

andrea.crotti10:08:14

or I can just make the requests by hand otherwise

andrea.crotti10:08:31

there seem to be a few but don't look too maintained/up-to-date

genec11:08:35

@plexus Has anyone tried using this union types module? https://github.com/lambdaisland/uniontypes I'm trying to use it with :dependencies [[org.clojure/clojure "1.9.0-alpha17"] [lambdaisland/uniontypes "0.2.0"] but keep getting an error that it can't find locate spec on my class path. But I can use spec from other namespaces in my project. I'm stuck.šŸ˜•

plexus11:08:26

@genec the current version is 0.3.0, which uses the .alpha namespaces

genec11:08:05

@plexus thanks, I'll try it. coming from F# / OCaml, I was really excited to see union types.

genec11:08:39

@plexus the project page still says "0.2.0"

plexus11:08:25

PRs welcome

genec11:08:00

@plexus yup, will do, thanks for the help

derveloper13:08:42

hi, im in my very beginnings of my clojure journey and i have a question. i have a set of sets containing values that i want to intersect, for two simple sets it is working, what i'm trying is: `(clojure.set/intersection (set [(set [1 2 3]) (set [3 4 5]) (set [5 6 7])])) ; not the expected result => #{#{7 6 5} #{4 3 5} #{1 3 2}} (clojure.set/intersection (set [1 2 3]) (set [3 4 5])) ;simple and expected result => #{3}`

genec13:08:31

you could use (apply intersection [set1 set2 set3]) and that will return a set with any element common to all 3 sets

genec13:08:42

(clojure.set/intersection (set [1 2 3]) (set [3 4 5]) (set [3 5 6 7])) -> #{3} (apply clojure.set/intersection [(set [1 2 3]) (set [3 4 5]) (set [3 5 6 7])]) -> #{3}

genec13:08:44

@derveloper is that what you are trying to do?

derveloper13:08:43

Yes, thanks!

chrisjd13:08:08

Alternative solution is (reduce clojure.set/intersection foo) where foo is your set of sets.

lmergen14:08:25

can anyone explain to me why derive requires keywords to be fully qualified ? it seems like a weird requirement ā€” furthermore, this requirement seems to go away when youā€™re using a custom hierarchy

chrisjd15:08:02

@lmergen I believe it's ideological - since you're adding to the global hierarchy, enforcing qualified keywords avoids potential collisions. That's roughly how it's explained in Clojure Programming. I guess it is just an opinionated API, that's all.

lmergen15:08:30

that explains it šŸ‘

lmergen15:08:58

sounds reasonable

plexus15:08:18

I was somewhat surprised by this behavior:

plexus15:08:06

I would have expected "foo_1_20"... any suggestions on how to do this instead?

plexus15:08:47

ach šŸ™‚

noisesmith19:08:31

Does it make sense to write code that leverages the fact that calling a promise delivers to it? a pro: makes my code simpler a con: most people that read my code probably don't know what it's doing

chrisjd19:08:31

Whatā€™s wrong with deliver? From that snippet, the argument would be that itā€™s clearly not idiomaticā€¦ but maybe it makes sense in the wider context of your code.

noisesmith19:08:02

@chrisjd I was using #(deliver p %) as a callback arg, and realized "oh, wait, I could just use p instead and get the same result"

noisesmith19:08:53

though I guess one could argue for "if the callback is a promise, then the behavior of delivering to the promise is not surprising" - I don't know though

chrisjd19:08:38

If it doesnā€™t leak too much of your implementation then you could just make the function accept a promise instead of a callback, yeah. Then the API is that some result gets delivered to the promise that you give it. That seems 100% reasonable to me.

noisesmith19:08:55

well I don't need to change the function - calling a promise delivers to it

noisesmith19:08:16

but I'll just use a lambda that calls deliver, people are less likely to be confused reading that

chrisjd19:08:47

I didnā€™t realise that calling a promise delivered to it. šŸ™‚

noisesmith19:08:52

that's what my clojurebot snippet above was meant to show

lvh19:08:28

Thereā€™s a clojure project for using AWS Lambda I canā€™t remember the name of, it IIRC could take fns from the repl and upload them to lambda?

lvh19:08:42

for some reason Iā€™m remembering the name ā€œportholeā€ but thatā€™s not showing me anything

chrisjd19:08:32

@lvh I vaguely remember someone talking about this in #clojure-uk not too long agoā€¦ I donā€™t think this is it, but looks quite good: https://github.com/uswitch/lambada

lvh19:08:46

yeah, I found that but thatā€™s definitely not it šŸ™‚

lvh19:08:49

thanks though šŸ˜„

misha20:08:06

@noisesmith I think it is very similar situation as with sets and contains?

(#{:a :b} :a) ;; vs.
(contains? #{:a :b} :a)

lvh20:08:54

yes! Thanks šŸ™‚

cgrand21:08:42

It's pretty alpha so let us know of any issues.

misha20:08:39

although if set contains false... ĀÆ\(惄)/ĀÆ

noisesmith20:08:44

@misha or hash maps or keywords for lookup

misha20:08:22

yes yes. but in case of hash maps it is a NullPointer opportunity

noisesmith20:08:54

There's an obscure one :) doesn't work with atoms though

misha20:08:54

I'd try to keep code: 1) consistent across clj/cljs where it'd make sense 2) keep different tricks at minimum level. Just to make sure I am not surprised myself in 2 weeks reading it.

misha20:08:49

Different skill/experience levels in a team might play role there as well.

noisesmith20:08:59

Yeah, I only discovered that feature of refs by accident, in a case that intuitively should have just been a "forgot to deref" bug

misha20:08:30

have not heard of it at all in 3 years, think it might be just an implementation side effect

noisesmith20:08:48

Why else would ref support IFn and this be callable? Vars do the same thing.

noisesmith20:08:53

Ref isn't doing the lookup, it's calling the object inside when called, just like a var.

misha20:08:56

on the other hand, I missed "nested reg-ex specs expect flat data structures" in spec guide after reading it like 7 times opieop

misha20:08:30

why would ref implement IFn, and atom/agent ā€“ not?

noisesmith20:08:35

Not sure, just saying implementation of a protocol isn't likely an accident it coincidence.

misha20:08:23

public final IFn fn() {
        return (IFn)this.deref();
    }
    public Object call() {
        return this.invoke();
    }
    public void run() {
        this.invoke();
    }
    public Object invoke() {
        return this.fn().invoke();
   }

noisesmith20:08:33

Refs and vars were older, maybe rh had second thoughts about the lookup and call pattern over time

misha20:08:45

someone really wanted to make sure it could be called

noisesmith20:08:28

That's what implimenting IFn looks like

noisesmith20:08:03

I like that invoke trick and I'm going to steal it for my fixing-to lib

noisesmith20:08:04

(implementation of invoke is a pain in the butt, there's ,20 arities to define)

noisesmith21:08:27

Oh never mind, it still needs to define all the invoke arities

decoursin21:08:09

Is if a macro in Clojure? I can't seem to find its source code in Github.

Alex Miller (Clojure team)21:08:46

itā€™s a special form

Alex Miller (Clojure team)21:08:12

most conditional macros ultimately bottom out on if, but others of potential interest are things like when, cond, etc

juanjo.lenero23:08:05

Hi, is there a macro/special form that will allow me to conditionally evaluate some expression? If the condition fails the expression should disappear from the code. Something like this:

(into [] [1 (only-if true 2)]) ;; Expands to (into [] [1 2])
; => [1 2]

(into [] [1 (only-if false 2)]) ;; Expands to (into [] [1])
; => [1]