Fork me on GitHub
#beginners
<
2017-08-27
>
automattable04:08:27

I see a ton of resources for learning clojure so I’m a bit lost on where to start… is there one in particular that’s recommended for people who already know fp in other languages and have a basic understanding of lisp?

noisesmith04:08:01

http://4clojure.com has some good exercises, and when you solve them you can see other people's solutions

noisesmith04:08:31

also be sure to check out the cheatsheet https://clojure.org/api/cheatsheet

automattable04:08:54

cool! thanks for the links

noisesmith04:08:37

@automattable and for books, Joy of Clojure is perfect for someone coming from ML or Common Lisp and learning Clojure

automattable04:08:44

👍 I’m coming from haskell so that should be perfect

seancorfield04:08:51

@automattable Have you worked on the JVM before? If not, that's probably going to be the biggest shift coming from Haskell, other than Clojure having no type system 🙂

automattable04:08:22

not in a long time, but yes

automattable04:08:00

what’s so different about the jvm that would cause me issues?

automattable04:08:28

tbh, I’m expecting strict evaluation to be the thing that takes me longer to get used to

automattable04:08:53

(and I will definitely miss my types :P)

seancorfield04:08:38

Folks coming from non-JVM languages sometimes seem to struggle with tooling, classpaths, stacktraces etc.

seancorfield04:08:53

I think it depends on how you look at it.

seancorfield04:08:20

Some people do just fine.

seancorfield04:08:33

Just putting it out there as a possible hurdle 🙂

automattable04:08:33

ah I forgot about that sort of thing

automattable04:08:49

I’ve heard the stacktraces can be rough

automattable04:08:55

especially when macros get involved

seancorfield04:08:31

And especially when you have lazy sequences in play 🙂 (re: your comment about strict evaluation)

automattable04:08:47

maybe I’ll just only use total functions

seancorfield04:08:19

I personally feel the stacktraces aren't as bad as some people make out -- I think there are some heuristics you can quickly pick up to help ignore the "noise" in the stack traces.

seancorfield04:08:35

So what brings you to Clojure from Haskell @automattable ?

automattable04:08:58

interviewing for a clojure job soon

automattable04:08:09

they claim I don’t need to know it going in, but I figure it can’t hurt

automattable04:08:51

I’m pretty excited about it 🙂

seancorfield04:08:37

This is a good talk to watch about one of the unique aspects of Clojure https://vimeo.com/223309989

jakeb04:08:26

is there a good way to apply a vector of functions to corresponding members of a vector of values? i’m looking for

(f [inc dec square] [1 2 3])
> [2 1 9]

noisesmith04:08:56

@jakeb (map #(%1 %2) [inc dec square] [1 2 3])

jakeb04:08:25

oh dang, of course

jakeb04:08:28

nice, thanks

jakeb05:08:10

hmm, follow up question then

jakeb05:08:20

is there an easier way to do

(map #(map (fn [f v] (f v)) [inc dec] %) [[1 2] [3 4]])
> ((2 1) (4 3))

noisesmith05:08:24

ugh, it auto expanded, the input was (map #(map (juxt inc dec) %) ...)

noisesmith05:08:02

but clearly juxt isn't what you want at all

jakeb05:08:20

i’d been thinking juxt too

jakeb05:08:35

but yeah it seems not right

jakeb05:08:42

is there any function like (defn f-of-x [f x] (f x))?

jakeb05:08:56

it’s not apply, because x isn’t a seq

noisesmith05:08:40

yeah, #(%1 %2) is as close as you get

noisesmith05:08:15

unless you count (.call f x) but that isn't an object, it's not first class

jakeb05:08:58

cool cool

noisesmith05:08:47

misremembered the name of the method at first

noisesmith05:08:49

but to end up with something first class, you need to wrap it in a function, so you might as well embed (f x) instead of (.invoke f x)

jakeb05:08:16

is there some magic i’m not thinking of if that first function is identity?

jakeb05:08:54

as in,

(map #(map f-of-x [identity bt/pct-strs-to-num] %) vec-of-vecs)

jakeb05:08:31

earlier i actually had a map and was able to use clojure.algo.generic.functor.fmap

jakeb05:08:36

but now i’m just trying to map a function over the second item in each tuple in a vector

donyorm10:08:04

@jakeb I'm wondering if a reduce statement is a better fit for your scenario, but I'm not in a position to fully flesh out the options

timo11:08:40

hi there

timo11:08:17

I would like to use something like this (take 3 (iterate plus now (days 1))), that I found on the website https://github.com/dm3/clojure.java-time#an-appetizer

timo11:08:46

it says ArityException Wrong number of args (3) passed to: core/iterate clojure.lang.AFn.throwArity (AFn.java:429)

timo11:08:08

I understand that there are too many arguments for iterate

timo11:08:26

any good advise how to rewrite the function?

motoom11:08:40

Too many or too few? The error message only tells you that there are a 'wrong number'.

timo11:08:06

I think iterate takes only two args

motoom11:08:18

What does (doc iterate) say?

timo11:08:12

should I try with a partial?

motoom11:08:26

(take 3 (iterate inc 1)) -> 1 2 3

motoom11:08:05

What are you trying to achieve? Determine the next three days, starting from today?

timo11:08:50

tried this (take 5 (iterate (partial plus now) (days 1)))

timo11:08:53

says ClassCastException java.time.LocalDate cannot be cast to java.time.temporal.TemporalAmount java-time.temporal/t-plus (temporal.clj:293)

jakeb20:08:39

so

(into {} [(vector 1 90)])
> {1 90}
(into {} [(list 1 90)])
> ClassCastException java.lang.Long cannot be cast to java.util.Map$Entry

jakeb20:08:14

what’s going on here?

dpsutton20:08:27

vectors are interpreted as key/value pairs. notice:

user=> (seq {:a :a :b :b})
([:a :a] [:b :b])

dpsutton20:08:43

so (into {} [(vector 1 90)]) is (into {} [[1 90]]) which is, in english, turn this vector of key/value pairs into a map, which is straight forward. but this notion of key/value pairs is not tied to sequential things but to vectors.

dpsutton21:08:03

here's the java of the cons function on hashmap that is being called:

jakeb21:08:42

interesting

jakeb21:08:01

i’d been using vectors for my key value pairs but I’d figured that was just convention

jakeb21:08:07

not something real

jakeb21:08:53

ok cool, changed a map to a mapv upstream and everything’s great