PurelyFunctional.tv Newsletter 376: Learn from core

Free Beginner Workshop

From OO to Clojure Workshop!

Watch my free workshop to help you learn Clojure faster and shift your paradigm to functional.

Issue 376 - May 04, 2020 · Archives · Subscribe

Clojure Tip 💡

Learn from core

Last week I talked about how Clojure's standard library gives us a leg up over JavaScript. A few people mentioned that many people will use lodash or a similar library when using JavaScript. That's true but it's not really what I was getting at. It's not just "is there a standard library or not?" There is something about a well-crafted standard library that gives you a leg up mentally, not just in code savings. In other words, a good standard library gives you tools for thinking and without it, you probably wouldn't come up with the same solution.

For example, would I have written frequencies myself if I wasn't used to using it in Clojure? I'm sure I could have written it myself, given the spec. But would I have thought of writing it? Would I have come up with that spec? Clojure has changed the way I think. Changing the way people think is the biggest impact Clojure will have on the industry.

lodash (like Underscore before it) is also very good. In fact, there's a bootcamp here in town whose JavaScript curriculum is based on re-implementing all of lodash. Students learn how things work by building it themselves. Like Clojure, lodash gives you small, powerful, general operations that you could implement yourself. By implementing them, you internalize a way of thinking. You change how you approach a problem.

Clojure has an excellent standard library. There is a lot to learn in the selection of functions it contains. This is essentially the message behind the book Clojure, The Essential Reference. In it, Renzo Borgatti walks through a huge portion of Clojure core. He's discovered a lot of great stuff and shared it in the book.

So that's my tip for the week: read core. There's a lot of good stuff there and it will make you a better programmer.

Quarantine update 😷

I know a lot of people are going through tougher times than I am. If you, for any reason, can't afford my courses, and you think the courses will help you, please hit reply and I will set you up. It's a small gesture I can make, but it might help.

I don't want to shame you or anybody that we should be using this time to work on our skills. The number one priority is your health and safety. I know I haven't been able to work very much, let alone learn some new skill. But if learning Clojure is important to you, and you can't afford it, just hit reply and I'll set you up. Keeping busy can keep us sane.

Stay healthy. Wash your hands. Stay at home. Wear a mask. Take care of loved ones.

Clojure Challenge 🤔

Last week's challenge

The challenge in Issue 375 was to score poker hands, taking into account high cards and kickers. You can see the submissions here.

You can leave comments on these submissions in the gist itself. Please leave comments! You can also hit the Subscribe button to keep abreast of the comments. We're all here to learn.

This week's challenge

Distance to nearest vowel

Write a function that takes a string as argument. Each character in the string will be a letter. The function should return a sequence containing the distances from each corresponding letter in the string to the nearest vowel in the string.

For example:

(nearest-vowels "aeiou") ;=> [0 0 0 0 0]  ;; if the letter is a vowel, the 
distance is 0
(nearest-vowels "babbb") ;=> [1 0 1 2 3]
(nearest-vowels "babbba") ;=> [1 0 1 2 1 0]

Notes:

  • All input strings will contain at least one vowel and all letters.
  • Vowels are a, e, i, o, and u.

Thanks to this site for the challenge idea where it is considered Expert level in JavaScript.

You can also find these same instructions here. I might update them to correct errors and clarify the descriptions. That's also where submissions will be posted.

As usual, please reply to this email and let me know what you tried. I'll collect them up and share them in the next issue. If you don't want me to share your submission, let me know.

Rock on!
Eric Normand