Fork me on GitHub
#beginners
<
2017-02-04
>
eslachance04:02:54

I'm going to bet one of you has a clever, much shorter way of turning the string GUILD_CREATE into the keyword :guilds (also MESSAGE_CREATE into :messages, etc) rather than this unwieldly thing: (keyword (str (clojure.string/lower-case (first (clojure.string/split "GUILD_CREATE" #"_"))) "s"))

dpsutton04:02:17

just to start with, you can easily aid in reading by threading it through

dpsutton04:02:47

oh, missed the pluralize part

seancorfield04:02:16

Or maybe (defn pluralize [s] (-> s (str/replace #"(.*)_.*" "$1s") str/lower-case keyword)) if you like regex.

seancorfield04:02:21

Pity that Java regex doesn't support Perl conversions otherwise (str/replace s #"(.*)_.*" "\L$1s") would be sufficient...

seancorfield04:02:49

Hmm, "\\L$1s" I guess, given Java's escape sequence rules 🙂

eslachance05:02:43

Ended up going with (-> (str/split "GUILD_CREATE" #"_") first str/lower-case)

eslachance05:02:11

Turns out there was already an automatic pluralize in the function I was calling this data with 😄

gryffindorstudent16:02:33

Hi, I'm writing a nested loop of sorts to traverse a matrix. I'm using something like (loop [r 0] (loop [c 0] ...)) to represent the row and col numbers, but when (= c 7) I need to go to the next row, while calling recur will only let me rebind c. How can I increment r?

schmee17:02:26

gryffindorstudent could you post some more context?

roelof18:02:08

What does age be here :

(= :age (let [age 9] (quote age))) 

roelof18:02:24

:age and "age" give a wrong test

mruzekw18:02:55

Not too sure what you’re asking but try ‘age

roelof18:02:18

I try to solve this one of the clojure koans :

"You can quote symbols as well as lists... without evaluation!"
  (= `age (let [age 9] (quote age)))

roelof18:02:46

and

`age ` 
is not working

mruzekw18:02:20

There’s and ’`

roelof18:02:03

thanks, the last one worked

roelof18:02:29

I thought ' was the quote symbol but I think I was wrong

mruzekw18:02:52

What’s your import/require like?

eslachance23:02:55

how would I chain str/replace-first?

eslachance23:02:15

(-> (str/split (message :content) #" ") first (str/replace-first "what here? %1?" #"!" ""))

eslachance23:02:54

(in other words how do I chain a function with a multiple arity)

rads23:02:52

@eslachance: when you use -> you leave out the first argument

eslachance23:02:15

I... googled and with some help figured it out too

eslachance23:02:28

here, actually, (-> (str/split (message :content) #" ") first (str/replace-first (config :prefix) "")) (my final code)

eslachance23:02:38

it's beautiful. I love threading macros

rads23:02:50

nice 🙂

eslachance23:02:40

Honestly my biggest issue is, I just don't know all the terminology. I thought "chaining function" but if I'd googled "threading macro" I would have found it right away

rads23:02:12

that macro allows you to write an explicit symbol to say where the threading happens

eslachance23:02:34

oh right! yes I sort of remembered that, somehow.

eslachance23:02:07

so (as-> 0 n (inc n) (inc n)) is the same as (-> 0 inc inc) in this particular case

eslachance23:02:57

I am going to have so much fun doing clojure tutorial videos.