PurelyFunctional.tv Newsletter 389: repl withdrawal

Issue 389 - August 03, 2020 · Archives · Subscribe

Clojure Tip 💡

repl withdrawal

I've been learning Next.js, which is a JavaScript framework that takes a lot of the modern best practices to heart. So I'm writing a lot of JavaScript and I am really missing the REPL. People often ask what the difference is between JavaScript's prompt and a Lisp REPL. So let's get into it.

Let me be really clear: JavaScript (Node and the browser) have prompts where you can type in code and execute it. That's important. If I want to know how Array.from() works, I can fire up a JS prompt and test it out. Great!

But what about figuring out what my function does when I pass it an empty array? Or what does this library function return under the data key? And what if I fix my function? How do I reload it into the prompt?

And now, with Babel, code is transpiled. You are writing in a different language from what Node can run. Can you write in that language in your prompt?

JS has a prompt, but it's not a REPL. I'm talking about running code in the context of the application with all of the modules and language extensions available. I don't think it exists, though it is technically possible to build. The stuff Next.js does for you took a lot of work to get right. I think it would require just as much work to turn the prompt into something you could live in to build your application.

Why do I miss the REPL? I've built up a lot of good habits in Clojure. I write a small amount of code before I check it in the REPL. I make sure I understand what code will do before I insert it into a production system. I tune the size of the chunk of code to the difficulty of it. That helps me get into flow. After a quarter hour of Clojure coding, I'm in the zone. I miss the zone.

We're very lucky in the Clojure world. More than FP, more than homoiconicity, more than being hosted, Clojure's main advantage is its REPL experience.

Podcast episode🎙

What makes some APIs cross a line into a Domain Specific Language? That's the question I ask in my new podcast episode. I've been asking myself the question for a long time, and I finally found an answer I liked in Lisp: A language for stratified design.

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 388 was to implement English-language title case. You can find the submissions here.

Please do participate in the discussion on the gist where the submissions are hosted. It's active and it's a great way to get comments on your code.

This week's challenge

The Frugal Gentleman

George likes to appear generous, but he's also very frugal, especially when he buys wine. Here's his strategy: if there are two or more wines to choose from, he buys the second cheapest. That way, he doesn't appear to buy the cheapest, but he avoid buying the more expensive options. Write a function that takes a collection of wines and returns the name of George's choice.

Examples

(choose-wine [{:name "White" :price 10.99}
              {:name "Red"   :price 8.74}
          
    {:name "Rosé"  :price 12.22}]) ;=> "White"

(choose-wine [{:name "White" :price 10.99}]) ;=> "White"

(choose-wine [{:name "White" :price 10.99}
              {:name "Rosé"  :price 12.22}]) ;=> "Rosé"

Thanks to this site for the challenge idea where it is considered Hard level in Ruby.

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. And there's a great discussion!

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