Fork me on GitHub
#beginners
<
2018-03-21
>
seancorfield00:03:11

Yes, that's it!

seancorfield00:03:22

And you can use get-in to navigate into the job hash map to pull out the pieces you need: (get-in job ["new_job" "id"]) -- since it looks like your hash maps have string keys, not keywords?

brnbraga9500:03:23

yes, that is exactly what I need, I suppose to generate the value I could do something like:

{:type (get-in job ["new_job" "type"]) :urgent (get-in job ["new_job" "id"])}

brnbraga9500:03:02

there is definitely a more general way for the value, I will figure out

brnbraga9500:03:07

thanks @seancorfield

brnbraga9500:03:21

I can just use dissoc for id

seancorfield00:03:36

@brnbraga95 You might also want to look at select-keys

brnbraga9500:03:06

it is incredible how much can be achieved with so little code

brnbraga9500:03:20

althought it is indeed hard to read (for beginners at least)

seancorfield00:03:45

Clojure's conciseness is both a strength and a weakness. Learning to write (concise) idiomatic Clojure takes time. I look back at some of my early Clojure code (which is still in production) and I shudder. My recent Clojure code looks much cleaner and easier to read (albeit likely requiring more experience of the readers).

seancorfield00:03:19

I got started learning Clojure back in 2010 and we first started using it in production at work in 2011.

brnbraga9501:03:35

awesome, the closest I have been from such a funcional programming was with some javascript functions, which is not considered a functional language but some libraries provide it. Now I am working on a project that runs heavily with Clojure, so I am getting ahead and doing my share of study, clojure with datomic are the main things on this project, I feel like I am changing my way of thinking in terms of programming because of all these funcional programming and these immutability concepts..sure is very different for someone new.

russ76712:03:50

Take heart, in the not too distant future you will find yourself wondering what all the fuss was about. It's one of the things that makes functional programming hard to explain is that the idea are actually very simple, it's getting used to the fact that you can get so much done with so little that takes time.

seancorfield01:03:34

@brnbraga95 Yeah, getting into a Functional Programming frame of mind can be hard, especially for folks whose only programming experience is something like Java -- where it's nearly all about stuffing data into objects and mutating it to get work done. Often you have to "unlearn" a whole bunch of (bad) habits in order to really get comfortable with FP. I really like this style -- but I was lucky to have studied it back at university in the early 80's, even tho' I had to learn C, COBOL, and later C++ in order to be employable πŸ™‚

gklijs08:03:28

Some people get the functional mindset easier than others. I had a Haskell course in college where almost everybody failed because they did not get it. I’m not sure how the little Haskell made it easier to get to Clojure.

mailmeupinside08:03:03

functional programming is often taught in the wrong way same goes for programming to be honest, I've had it in my vocational school and practically nobody who didn't program before "got" it

mailmeupinside08:03:43

by the way, what do you use to store data on the disk? text files? SQLite? something else?

seancorfield16:03:24

We use MySQL very heavily. We also use MongoDB a bit. We've also experimented with Amazon's DynamoDB. And we are starting to use Redis quite a bit (for a few, very specific things).

seancorfield16:03:46

I'd love to find a place for Datomic in our stack at work but we don't fit its use cases, for the most part. A lot of our tables are very high write and/or append-only but very large.

seancorfield17:03:01

Datomic would be a good fit for our e-commerce subsystem, I suspect, and possibly for our member-profiles, but very little else in our system -- so it's not worth the complexity of introducing a whole new DB stack just for a couple of subsystems (when we already have those subsystems working satisfactorily with MySQL).

hawari.rahman1708:03:22

After reading Eric Normand's wonderful take on this whole paradigm/mindset thing: https://lispcast.com/procedural-paradox/ I think that a lot of newcomers on FP such as myself finds it hard to fully understands FP because we tend to get stranded to "easier to understand" but cliche explanation on FP (immutable vars, higher order function, pure function, etc.), instead of what FP paradigm really means (use function to produce a solution).

mailmeupinside09:03:31

The Haskell Book also is a wonderful FP resource http://haskellbook.com/

saurabhkukade17:03:11

re-find should boolean right?

firthh17:03:06

it returns a string or nil which you could treat as truthy or falsey values - http://clojuredocs.org/clojure.core/re-find

ghadi17:03:23

re-find returns a full match string if no regex captures, else a vector of captures, else nil

saurabhkukade17:03:08

so there is no function to which we can pass regex and string that will return 'true' or 'false' if matches and not matches resp?

russ76717:03:42

I think if you are looking for an explicit true or false you can always wrap the boolean function around what you are doing: (boolean 1) => true

russ76717:03:26

But if you are just working in a Clojure context then the truthy logic works just the way you want it to.

saurabhkukade17:03:20

yeah got it. I wrapped that function to boolean finally. Thanks:grinning:

sifou93520:03:28

why is (-> 3 identity) evaluates to 3 but (-> 3 (fn [x] x)) we get Error?

sundarj20:03:34

compare (macroexpand '(-> 3 identity)) with (macroexpand '(-> 3 (fn [x] x)))

sifou93520:03:26

@ @ Thank you! when I put symbol to fn it expands, but the when I put the fn it throws error when when it expands. I forgot it’s a macro!

sifou93520:03:47

the right way would be I guess (-> 3 ((fn [x] x)))

sundarj20:03:14

yep! -> (and the other arrow macros), are just dumb code transforms; -> merely writes the value into the first position of the lists/symbols you pass it

sundarj20:03:44

so (-> 3 (fn [x] x)) becomes (fn 3 [x] x) which isn't valid πŸ™‚

sundarj20:03:21

and yeah, wrapping it with parens means it becomes ((fn [x] x) 3) instead

sifou93520:03:16

Thank you πŸ™‚

rauh20:03:51

@sifou935 Try macroexpanding

mailmeupinside21:03:44

do you ever use if alone instead of if some? when checking if a given thing exists? why does this implicit nil to false conversion even exist?

alexmiller21:03:40

when: all the time

andy.fingerhut21:03:43

I believe it is very common among Clojure programmers to do (if <expression> ...) where they rely on <expression> returning nil being treated as false.

alexmiller21:03:13

also, it’s not a conversion rather the definition of logical truth in the language

mailmeupinside21:03:26

what if you want to check if it exists and it's false? πŸ€” I mean yeah, use if some? but one can get carried away

andy.fingerhut21:03:54

(if (= false <expression> ...) would work, as would (if (false? <expression> ...)

alexmiller21:03:05

then you can use the predicate false? to check specifically for a false value

alexmiller21:03:50

but practically speaking, Clojure leans heavily on its notion of logical truth everywhere

mailmeupinside21:03:00

what do you think about this post

andy.fingerhut21:03:31

Regarding the first point, I think there are many people who would agree about avoiding "use", but still find :refer palatable, because at least with an explicit :refer, the text of the code still lets you see where the :refer'd name came from.

alexmiller21:03:03

I agree with some of that and disagree with some of that post (like the nil parts :)

mailmeupinside21:03:47

I've seen expanded opts everywhere

russ76721:03:20

@mailmeupinside The whole 'nil and false is treated as falsy' has a history that predates Clojure by decades. It's a different way of looking at things but my experience has been that it works fine.

mailmeupinside21:03:04

alright, if it's working I'm ok with it :)

russ76721:03:28

Sorry, that's not how these things are supposed to go! You are supposed to tell me I'm crazy and I make some snarky comment back and then... and then...

mfiano21:03:12

Are there any other video tutorials for a small project in Clojure such as Parens of the Dead? I read a few books, and I think I'm ready to jump in with a little guidance.

russ76721:03:28

@mailmeupinside On the other hand I am a fan of the name things in a series of let bindings vs mashing them together in a single expression style.

mailmeupinside21:03:49

I used to mash them, but today I tried that let approach and it's actually a lot more convenient and readable, yeah

mfiano21:03:31

I'm kind of looking for something that focuses on the reference types, and bonus points for applications in concurrency.

mailmeupinside21:03:01

thanks all for the input πŸ™

alexmiller21:03:11

happy clojuring!