Fork me on GitHub
#beginners
<
2016-06-30
>
petrus10:06:48

how do I turn a BufferedInputStream into a string? mock.request returns response :body as buffered input stream, and I just want to print it out

surreal.analysis11:06:42

@petrus: I believe just using slurp will work

surreal.analysis11:06:53

Ah, as someone mentioned on SO

gowder16:06:18

Can I ask a really stupid question? Sorry... but...

gowder16:06:44

is this using case right?

(defn colorize [name]
  (case name
    @curpage :red
    :black))

gowder16:06:40

what I think this should do is deref the curpage atom and then return :red if it's the same as the name, or black otherwise. but for whatever reason it's always returning black...

tmtwd16:06:38

yeah that should be right

gowder16:06:45

thanks @tmtwd. I thought so, but I'm running into a really weird bug...

akiva16:06:47

Nope, that won’t work.

tmtwd16:06:49

that is odd behaviour you’ve found

akiva16:06:57

case does no evaluation.

gowder16:06:13

oh, so it's like passing in a quoted form or something?

akiva16:06:26

It only works with literals. Strings, numbers, etc. Nothing it has to interpret or change.

akiva16:06:46

You could wrap it with a let, though, and grab the deref’d value.

gowder17:06:09

ooooooh. thanks @akiva! this is what I get for being fancy with my conditionals.

jswart17:06:45

You can do the same with cond

jswart17:06:55

and have it evaluate

jswart17:06:27

Though case seems to be kind of weird, because you don’t seem to do anything with name. You may have elided it though.

jswart17:06:51

If that is your whole function though I would just use if rather than case or condp

jswart17:06:13

(if @curpage :red :black)

jswart17:06:32

which is what the cond is doing.

akiva17:06:58

I think it’d be (if (= @curpage name) :red :black), wouldn’t it?

jswart17:06:43

yep, woops

jswart17:06:01

and no :else in the condp either. You just put :black as the last expr.

jswart17:06:15

REPL > memory

akiva17:06:53

Yeah. :else is optional in cond.

jswart17:06:10

you can’t add it

jswart17:06:17

or it will try to match on :else

jswart17:06:36

(if (= name :else) …) which we don’t want

jswart17:06:52

anything not specified we want to return :black

jswart17:06:15

putting in the :else :black line and running (colorize :foo) would throw an exception

jswart17:06:51

Note to self: check with the REPL first.

montanonic19:06:35

Any recommendations for getting setup with an IDE? I'm used to text-editors like Atom; not an emacs/vim person.

montanonic19:06:57

I heard some people recommend lighttable? which I installed, but not sure how to set it up with the best plugins

st19:06:07

@montanonic: I’m super happy with cursive (IntelliJ plugin). IMO worth trying (at least)

montanonic19:06:20

okay, thank you 🙂

st19:06:35

@montanonic: you’re welcome. (in case there is #C0744GXCJ channel)

senya2219:06:14

why does the put get blocked for an unbounded channel?

senya2219:06:38

(def ch (chan))

senya2219:06:51

(>!! ch "hello")

senya2219:06:27

shouldn't the take be blocking instead?

donaldball19:06:53

It’s not unbounded, it’s unbuffered

donaldball19:06:06

Pretty sure Rich’s statement on unbounded channels is NO

senya2219:06:30

does it mean (chan) is prohibited?

senya2219:06:59

or does it mean it doesn't allocate any buffer by default?

donaldball19:06:04

No, just that it’s unbuffered; writes and reads will block until there’s a counterparty

senya2219:06:50

yeah, but why does the write block? the take doesn't seem to unblock it

donaldball19:06:58

I don’t see a take in your example

donaldball19:06:06

sparkfund.api.repl=> (def c (clojure.core.async/chan))
#'sparkfund.api.repl/c
sparkfund.api.repl=> (future (clojure.core.async/>!! c 1))
#object[clojure.core$future_call$reify__8947 0x1519d302 {:status :pending, :val nil}]
sparkfund.api.repl=> (clojure.core.async/<!! c)
1

donaldball19:06:52

If you want a buffered channel, just supply the size as the arg to chan and you’re good to go

bsima19:06:00

anyone have experience with ztellman's automat library? I'm trying to grok it and having trouble internalizing FSM's in general

hrathod19:06:00

@montanonic: If you like Atom, you might want to check out https://github.com/jasongilman/proto-repl

montanonic19:06:46

Thanks for letting me know. Currently I have cursive set up so I'll see how it fares me.

senya2219:06:40

interestingly, for me the (future (>!! ch "hi")) blocks as well

senya2219:06:34

I didn't list the take part of the code just because I found that it's been blocked on the put

senya2219:06:24

I'm using IntelliJ Clojure plugin, I guess it behaves differently from a regular REPL?

donaldball19:06:48

… that would be surprising?

senya2220:06:16

ah, it seems to be spawning a new thread which needs to be interrupted for the normal behavior to work: `(future (>!! ch "hi")) Evaluation interrupted. => #object[clojure.core$future_call$reify__6736 0x13cd362b {:status :pending, :val nil}] (println (<!! ch)) hello`

senya2220:06:29

`(future (>!! ch "hi")) Evaluation interrupted. => #object[clojure.core$future_call$reify__6736 0x13cd362b {:status :pending, :val nil}] (println (<!! ch)) hello`

niall20:06:03

Hi guys - I'm someone who's been experimenting with clojure and im excited by the possibility of using clojurescript to never have to write javascript again 😄

niall20:06:20

any tips about weathe to learn om or reagent or something else - just for hacking - nothing to serious at the minute

tmtwd20:06:08

I would go with reagent

niall20:06:15

that's what it was looking like from googling about

niall20:06:34

thanks for the confirmation...just need to think of something cool to write now...

hrathod20:06:11

@niall: You may find this interesting: https://github.com/Day8/re-frame

hrathod20:06:53

it's intermediate level, but the philosophy is worth thinking about

niall20:06:57

ok sounds interesting - tbh my mind is still rather blown from functional programming...im only just recovering

niall20:06:32

looks like the framework might help get over the blank page syndrome a bit

hrathod20:06:39

@niall: There is also #C0620C0C8 and #C03S1L9DN if you need

niall20:06:30

i will! while you're all being so helpful, i have anothe noob question. I have a feel what what operations are fast and slow in other languages, but not yet in clojure

niall20:06:39

i wrote an enigma machine emulator

niall20:06:06

its slow - but I don't really know where to start to make it fast

niall20:06:54

g2g - thanks everyone!

jswart20:06:26

those could be slow^

jswart20:06:42

Running map multiple times over a sequence.

jswart20:06:09

(map h (map g (map f xs))) vs. (map (comp h g f) xs)

nathansmutz21:06:48

For lein with Clojurescript, can you set compiler optimizations from a profile? I used with-profile to pick a profile with :optimizations :advanced but I'm seeing comments in the produced javascript.

polymeris21:06:26

Hi. I just installed the new relic app monitor, and to my surprise it reports 100s of threads running on the JVM. I use plenty of futures, but I thought they came from a limited pool?

danlebrero21:06:04

@polymeris: futures use an unbounded pool

polymeris21:06:55

thanks, @danlebrero I thought I had read somewhere they used a fixed size pool

danlebrero21:06:27

@polymeris: a fixed pool is used in agent's "send" fn. Note that send-off uses an unlimited pool