Recurse Center: Week Three
This post is about my third week at the Recurse Center.
Functional Programming and Clojure
During this week, I continued reading Clojure for the Brave and True, and completed the next two chapters (Clojure Alchemy: Reading, Evaluation, and Macros, and Writing Macros). Reading about how Clojure syntax is read and evaluated was very interesting! It reminded me of my first project, Crisp: a simple Lisp interpreter.
During the previous week, while reading Brave Clojure’s 4th and 5th chapters, I was briefly introduced to some of the key tenets of functional programming. I found these concepts very fascinating. This week, I spent a considerable amount of time reading about them. While I would like to write a separate post on my findings, here are some of the points I have taken on my notebook:
- Functional programming is characterized by its use of pure functions.
- A pure function is one that has no side effects.
- The values evaluated by a pure function are solely dependent on its arguments. The return value for a given set of arguments, will always be the same, irrespective of the number of times the function is called or when it is being invoked. This makes it easier to do parallel programming, testing, and using higher-order functions
- Because of their deterministic nature, a pure function can be replaced with its return value, in an expression (referential transparency)
- The use of impure functions is not prohibited. But as a functional programmer, it is important to be wary of using side effects.
- As changing the value of a data-structure can cause side effects, functional programming emphasizes the use of immutable data-structures.
- As we need to need to change the state of local variables to run a loop, recursion should be preferred over loops
RemindMe: My First Clojure App
Now that I was getting slightly familiar with the world of Clojure, I thought it would be the perfect time to embark on a journey to build my very first app using Clojure. I decided to build an online version of flash cards, called RemindMe.
So, I spent a day writing the server-side logic of RemindMe, using Node.js. I then proceeded to build the front-end part of the project. To implement the front-end part, I used the Bootstrap framework. This Bootstrap tutorial was very helpful, to get started. (Side note: Long after finishing the front-end part, I realized that the hamburger menu on the navigation bar is not working on a mobile display. I’ll need to fix this; would love to pair with anyone who is good with Bootstrap/CSS!).
The Node.js version of RemindMe is hosted on this GitHub repository.
After completing the app in Node.js, I proceeded to re-implement the backend of RemindMe, using Clojure. I used the Ring framework and it’s jetty-adaptor to build my web service. I chose Compojure as a routing library, for better handling of requests.
RemindMe is deployed here: https://remind.otee.dev.
Here’s a detailed account of how I built RemindMe, using Clojure, Ring and Compojure: https://otee.dev/2022/01/25/clojure-backend-using-ring-jetty-compojure.html
- I solved these LeetCode problems during this week: Calculate Money in LeetCode Bank (my solution), Determine Color of a Chessboard Square (my solution) Longest Increasing Subsequence(my solution), Maximal Square(my solution)
- My article on Lazy Sequences in Clojure got featured on Clojure Deref!
- This article was also a part of Recurse Center’s Joy of Computing Blog!