Fork me on GitHub
#beginners
<
2016-03-16
>
vigneshm07:03:30

Is it possible to specify placeholders while using the partial macro? Something like the following ` `

vigneshm07:03:18

` (defn foo [arg1 arg2] …) ((partial foo _ “arg2”) “arg1”) `

vigneshm07:03:46

Forgive bad formatting, slack noob here

bwstearns07:03:40

@vigneshm: I don't think (but I don't know for sure) you can easily partially apply out of order. You could do something like (#(foo % arg2) arg1)

vigneshm07:03:18

Nice. That is good enough for me

urbanslug08:03:55

How can I find out where to get Thread/sleep or how to find clojure libs?

bwstearns09:03:54

@urbanslug: Thread is accessible without any libs.

bwstearns09:03:50

(future (Thread/sleep 4000)
        (println "I'll print after 4 seconds"))
(println "I'll print immediately")

bwstearns09:03:01

in general if you're looking for useful libraries though check out http://www.clojure-toolbox.com/

lmergen14:03:20

what are the -> and ->> operators called?

lmergen14:03:30

i'm trying to figure out how to use them properly, and what the difference is

lmergen14:03:35

and googling is quite hard simple_smile

codonnell14:03:07

@lmergen: they're called threading operators I think

lmergen14:03:31

and i suppose the difference is whether they pass along their first or their last argument?

lmergen14:03:07

ok cool, thanks

danmidwood14:03:32

I generally call them "thread first" and "thread last"

lmergen14:03:11

so, i think someone needs to hold my hand a little bit with this, just as an excercise

danmidwood14:03:42

I'm not sure if they're official terms, but they're both commonly used and easily googleable

lmergen14:03:04

consider this code:

(defn by-email [email]
  (map #(dissoc % :password)
       (select user
               (where {:email email}))))
that could be rewritten to
(-> (select user
               (where {:email email}))
       (map #(dissoc % :password))))
right ?

lmergen14:03:24

or would i have to use ->> here?

lmergen14:03:27

i'm a bit confused

lmergen14:03:01

(and I expect i'm not the only Clojure newbie who's confused by this :))

danmidwood14:03:55

Yes, you'd use thread last ->>, because you want the result of the select to be the last element in the map invocation

lmergen14:03:43

yes, but, i am already using partial application of the map function, so it only accepts a single argument... or is this macro doing more magic under the hood?

lmergen14:03:47

(note: I'm coming from a Haskell background)

danmidwood14:03:01

The macros takes the result of the preceeding expression and "thread" it into the next one. So the thread first works like this, putting the result of the select expression where the underscore is in the map invocation (-> (select ....) (map _ some-fn))

lmergen14:03:16

ahhh right

danmidwood14:03:22

In your case, you want to use thread last ->> to put it at the end

lmergen14:03:22

so the macros actually parse the expressions

danmidwood14:03:45

(->> (select ....) (map some-fn _))

lmergen14:03:03

and what would i do if it sometimes requires the first, and sometimes requires the last argument?

lmergen14:03:32

probably using a flip kind of function?

codonnell14:03:39

There's another form called as-> which allows you to bind the argument passed to a name

danmidwood14:03:45

That's right. These threadings are macros that transform the contents

lmergen14:03:55

this helps with my mental picture

lmergen14:03:03

thanks for the help guys

codonnell14:03:00

You'll noticed that most of the sequence functions have the sequence as their last argument so they are amenable to ->>

lmergen14:03:13

and -> works best for functions that just accept a single argument

codonnell14:03:09

That's right. And most of the hash-map functions take the map as their first argument, as well.

samueldev14:03:04

anybody have any familiarity with reporting over sockets? likely using Sente https://github.com/ptaoussanis/sente

martinklepsch16:03:57

@lmergen: @codonnell @danmidwood: this is super handy if hard to google things come up: https://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

lmergen16:03:05

oh that's nice

tom19:03:50

I'm playing around with re-frame and re-com. It's going well. But I'm trying to figure out the best way to toggle a class on a list of anchor tags.

samueldev19:03:42

not-any? is a thing

samueldev19:03:50

how come there's no any?

tom19:03:26

@samueldev: What are you needing any? for?

samueldev19:03:50

I've got the following data structure: {:show-confirm-modal false :show-quit-modal false}

samueldev19:03:58

I want a specific element to show up if *either* of those are true

samueldev19:03:39

without manually doing (or (= true (:show-confirm-modal db)) (= true (:show-quit-modal db)))

tom19:03:13

One way is (some? true? (vals my-map))

tom19:03:29

But in general I don't know why there isn't any?. I'm not sure anyone knows.

lmergen19:03:45

wouldnt any? be the same as some?

bronsa19:03:08

some? isn't what you want, some is

vleis21:03:51

is it possible to use clojure to write middleware for a jruby rack app?