Fork me on GitHub
#beginners
<
2016-01-22
>
slester00:01:45

@chadhs: I like it OK, but it has an oldish version of Clojure so some of the fun new stuff that makes quality-of-life upgrades doesn't work

slester00:01:30

@chadhs [org.clojure/clojure "1.4.0"]

jonschoning00:01:51

Do people still use Refs or do people reach for core.async as the default now?

meow00:01:52

someone should create a modern version of the katas and 4closure type problems

meow00:01:19

@slester: is flatten considered cheating

jonschoning00:01:31

i.e. would you build an app architecture on Refs when you have core.async available

slester00:01:05

@meow: yes, it's re-implementing flatten 😛

meow00:01:43

cheat and look at the source for flatten

meow00:01:21

and mapcat and cat and concat

meow00:01:43

cheat - that's my advice - works for me

meow00:01:34

and look at the differences in the source implementation between clj and cljs

meow00:01:56

and then write a blog post about it

meow00:01:03

and then post a link here

meow00:01:09

go for it

meow00:01:14

you can do it

meow00:01:19

¯\(ツ)/¯

seancorfield00:01:48

@jonschoning: If you need a Ref, use a Ref. If you need core.async, use core.async. I don’t see them as related at all.

jonschoning00:01:57

well, i mean presumably one could use Refs and dosync to communiate state around an app, or use core.async w/ channels instead to do the same

seancorfield00:01:04

core.async is for asynchronous data communication between cooperating processes in your application. Ref is for managing multiple pieces of mutable state in a synchronized way.

jaredly00:01:31

@jonschoning: imo core.async is a bit harder to reason about, but more powerful + better for complex problems

jonschoning00:01:00

I guess in my view, "managing mutable state" seems similar to "asynchronous data communication between cooperating processes "

jonschoning00:01:35

especially if the "managing mutable state" is occuring on different threads

jonschoning00:01:03

@jaredly: yeah, that makes sense

seancorfield00:01:54

A core.async-based app may have mutable state or it may not have mutable state. A Ref-based app most definitely has mutable state. I would use those two things for very different purposes.

eggsyntax01:01:45

@chadhs: re: diff — are you sure? Works fine for me.

apiserver.core=> (diff #{1 2 3} #{})
[#{1 3 2} nil nil]

jonschoning01:01:16

@seancorfield: ok, I can see breaking it down like that provides the most clarity

seancorfield01:01:25

FWIW, we have ~10k lines of production Clojure with just 30 atoms and no refs. Most of those atoms are caches (mostly with TTL, via core.cache).

seancorfield01:01:53

We also have two or three agents (mostly used for logging and email sending).

seancorfield01:01:39

We were using core.async in one app — with Sente so we could send data back and forth over WebSockets easily — but we decided to discontinue work on that app and do things a different way.

jonschoning01:01:43

@seancorfield: ah ok... that makes sense. Just trying to get a feel if the Clojure community had really deprecated atoms/refs; this appears to not be the case at all; all the better.

seancorfield01:01:22

I think the use cases (between STM and core.async) are so different that they are purely complementary techniques.

jonschoning01:01:54

@seancorfield: I totally get where you're coming from and your clarifying point earlier made a good distinction. But at the same time, I don't think it's a stretch to say one could take a concurrent app that uses atoms/refs to communicate state between processes/threads, and rewrite it to use core.async instead. this would change some of the semantics, of course, but it would be serving the same goal from an application perspective

donaldball01:01:27

One could say that channels are for coordinating work; atoms are for shared state

dantsui02:01:29

Can I get some help understanding why the following working clojurescript throws when run in a clojure REPL? (I don’t understand why ‘rps’ is still an unbound variable in the 2nd snippet.) Thanks! https://gist.github.com/sdtsui/4026a4df7f4e08cff78c

mfikes03:01:05

@dantsui: You are using == which is only for comparing nums for equality. In ClojureScript it might work, but you are hopefully seeing WARNING: cljs.core/==, all arguments must be numbers

dantsui03:01:03

@mfikes: Ah, thank you. (not getting that error message, but ) I think the error on line 18 of my gist makes sense (trying to cast the String on say, line 5, to a Number) Checking it out..

dantsui03:01:05

Yup, that was it! Thanks again. simple_smile

chadhs03:01:56

@eggsyntax: yeah i jumped the gun, i was doing something to the nil that was returned that was causing my error

chadhs03:01:50

yeah remove doesn’t work with nil

chadhs04:01:57

ah… i can just coerce the resulting nil to be a set if it isn’t nil making a set a set is a noop so that works just dandy

Josh Horwitz04:01:43

@clojuregeek: Thanks for that site!

chadhs04:01:13

bummer clojure.set is available on 4clojure but not clojure.data

chadhs04:01:18

that stuff was in clojure 1.3 as well

mudphone05:01:14

I’m trying to get the first item in a coll that passes a predicate, like with some

mudphone05:01:29

but, I need it to return the item itself, and not the result of the expression

mudphone05:01:51

Like this (some #(= (:content %) 2) [{:content 2} {:a 3}])

mudphone05:01:06

but, that returns nil and I want it to return {:content 2}

mudphone05:01:22

this works, but is klunky: (some #(and (= (:content %) 2) %) [{:content 2} {:a 3}])

mfikes05:01:37

@mudphone: (first (filter pred coll)) is very close to the English “first item in a coll that passes a predicate” If you defined (def ffilter (comp first filter)), then that would be shorter but then you’d have the problem that ffilter is not well known—hrm.

mudphone05:01:23

@mfikes: ah yes, thanks!

mudphone05:01:33

for some reason, I as afraid of the empty list returned by filter

mudphone05:01:41

but, first on empty list is just nil

slester18:01:00

are there any podcasts/videos you'd recommend watching while I do other things? just clojureTV on youtube?

slester18:01:27

although a user named emacsrocks is going to make me feel bad since I'm the lone person using Clojure and vim 😛

shaun-mahood18:01:17

Also, the emacsrocks channel has parens of the dead on it

csmith20:01:40

@slester: I switched to spacemacs eventually, but used vim for a while with Clojure

csmith20:01:10

with Fireplace and some other stuff, I thought it worked well enough. Never found a sane way to make vim work with ClojureScript though really. Just FWIW

csmith20:01:21

(so you aren’t the only one simple_smile )

gerred20:01:52

I'm liking Cursive, but I'm still going to check out Emacs - IntelliJ is project-crazy.

gerred20:01:04

@shaun-mahood: how are the LispCast core.async and clojure.test tutorials?

shaun-mahood20:01:41

@gerred: Not sure, I still have to get around to watching them.

shaun-mahood20:01:15

Have you tried core.async at all? Timothy Baldridge has a bunch of episodes on his site as well ( https://tbaldridge.pivotshare.com/ ) and he was heavily involved in the development of core.async

shaun-mahood20:01:54

The original paper is pretty interesting too, it's one of approximately 2 actual computer science papers I've read through completely

gerred20:01:27

I haven't yet, making the transition from Erlang / Haskell, so I'm very excited to check it out.

gerred20:01:48

This is actually more the format I was looking for, rather than larger-scale classes. Quick bit then move on.

gerred20:01:34

@tbaldridge: @shaun-mahood is up in here bringing you sales. 😉

shaun-mahood20:01:48

Oh nice. The only other computer science thing that I read was Joe Armstrong's thesis 😉

gerred20:01:53

ooh, nice.

gerred20:01:58

a good one.

shaun-mahood20:01:12

Yeah they actually were both super interesting. Haven't used anything from either of them though!

gerred20:01:34

I'm historically a vim user, but Cursive has blown me away, minus the fact that it's so focused as an IDE when sometimes I just want my code and a repl.

gerred20:01:50

but I'm so wired for vim that emacs is a pain.

shaun-mahood20:01:16

Cursive is really amazing. Can you map your vim shortcuts over? I'm pretty useless in both Emacs and Vim, so it's been amazingly nice for me.

csmith20:01:44

spacemacs really just feels like vim with a little work (albeit a little slow)

slester21:01:40

spacemacs is super super confusing to me

csmith21:01:08

understandable. One thing is, it is quite large. Take all of two big edditors and cram them together….

slester21:01:12

I don't like Cursive because the IDE feels like overkill

csmith21:01:29

with a little time, I was able to squint, use vim bindings and forget it wasn’t vim though, but have nice REPL integration

slester21:01:38

I don't like wading through dialog boxes to configure stuff, and I couldn't figure out how to get it to be even close to my vim setup

csmith21:01:34

yeah, configuring it is a bit of a tall order. Just wanted to provide one data point of someone that did the vim->emacs thing and liked it by using spacemacs.

csmith21:01:40

For a lot of stuff vim w/ fireplace works fine

slester21:01:04

I wanted to/tried to do spacemacs but just gave myself a headache 😞 good data point, I may not be smart enough to figure out how to use it well enough

csmith21:01:55

hah, no, I hope that’s not the take away simple_smile. FWIW, I had to put vim down a month before coming back to it. spacemacs was the same way. Weird, unapproachable and frustrating. If you think it’s worth trying, give it some time and ease into it

slester21:01:21

does emacs/spacemacs have rainbow parens?

gerred21:01:34

shaun-mahood: Haven't tried yet, but IdeaVIM by itself is amazing.

gerred21:01:46

I had a tough time with spacemacs too, really around projects.

shaun-mahood21:01:00

@gerred: I pretty much have what is essentially a scratch project open in Cursive all the time now and it sort of solves the project issue for me.

gerred21:01:26

that's a good idea.