Hey! I’m Abhinav

  • I write about code.
  • This is a blog of things that I find cool and want to share with you.
  • I’m currently interesed in functional programming and lisp (mostly Clojure).

The problem with python's map and filter...

… and how we might fix it. This is NOT a hate post. Let me say that again, This is NOT a hate post! Python is a fine language and it was my first programming language. Like the initial stages of falling in love with someone, you can’t see the flaws, the same was with python :) But as time goes by and the initial limerance fades, you start seeing the flaws....

November 27, 2021 · 9 min · Abhinav Omprakash

Macrobrew: Clojure macros distilled

I first read about the legendary lisp macros in Paul Graham’s essay, and since then my whole journey of learning lisp has been driven by a desire to fully understand the power of macros. If you have not heard about the power of lisp macros, here’s a quote from one of the creators of Scheme (a lisp) that captures the essence of this power. If you give someone Fortran, he has Fortran....

November 10, 2021 · 24 min · Abhinav Omprakash

Recursion is recursion is recursion is...

Defining recursion in terms of itself is an old joke among programmers. Despite the fact that it frustrates a lot of new-comers, we don’t change it. I like to define recursion as “Iteration for the cool kids”. I don’t mean this in a snobbish, let-us-exclude-the-for-loopers kinda way, but rather in a tone of appreciation. Recursion is an elegant way of doing things. Recursive alogrithms are concise, have less noise and have immutability baked in (always a plus)....

October 27, 2021 · 9 min · Abhinav Omprakash

Clojure Tutorial for Beginners 1

Welcome, young lisper. I see you have heard the summons from the mystical forces. Prepare yourself for a journey like no other. Your view of programming shall change, and change for the better. You must shed your past beliefs and practices. This is a new path, one that bears little resemblance to the paths you have trodden before. And that is a good thing. Initiation rites You have two options - either use an online one-click setup or bite the bullet and install clojure and other tools on your local machine....

August 30, 2021 · 8 min · Abhinav Omprakash

Hi Hugo, Bye Django

Introduction As you can see, there have been some (drastic?) changes to this site. It is much faster, the design is sleeker, and it looks like a completely different site. I can’t take credit for any of that. Except for the tiny green lowercase a favicon on top. My previous site was built with django, and I was running into some performance issues, I was about to look into caching mechanisms, and optimizing sql queries (requesting the front page resulted in 28 sql queries, tf?...

August 29, 2021 · 2 min · Abhinav Omprakash

Classes are dictionaries draped in syntactic silk.

In this post, we are going to see how we can implement classes if python didn’t come with a class construct, read till the end if you’d want to know why I put you made you go through all this pain fun😉 What the heck is a Class? There are a lot of philosophical discussions about what classes are but I’m not concerned with that. In the simplest terms, a class is an entity that has data and functionality related to that data, these are called attributes and methods....

August 25, 2021 · 10 min · Abhinav Omprakash

Fold is gold: understanding reduce

Introduction reduce or foldleft is a very powerful function, but it can be quite tricky to understand and use. In fact, I used to think that reduce was an obscure function, that reduced (hehe) the readability of a program. If you ever want to make it as a functional programmer, understanding reduce is as important as important as knowing how to reverse linked list. I’m joking, knowing how to reverse a linked list is not that important, and it can be done with reduce!...

July 11, 2021 · 10 min · Abhinav Omprakash

Understanding partial functions

Welcome to the land of contrived examples and imperfect metaphors. Today we will be visiting a store called the five-item store. You’re only allowed to buy five items, no more, no less. The moment we enter the store, a cashier sees us and begins tailing us, and he keeps repeating “give me your items for so that I can make a bill” over and over again, so we just pick up an item and give it to him, and he shrieks and says “give me all five at the same time or none at all....

June 7, 2021 · 8 min · Abhinav Omprakash

How to use timeit and pretty timeit

Here’s the situation, you have two algorithms in front of you, and you want to see which one is faster. Suppose we wanted to see what’s faster for constructing a list: a for loop, or a list comprehension. A simple solution might look like this. import time def number_list_1(count_up_to): lst=[] for i in range(count_up_to): lst.append(i) def number_list_2(count_up_to): lst=[i for i in range(count_up_to)] if __name__=="__main__": import time start = time.time() number_list_1(10000) end =time....

May 7, 2021 · 4 min · Abhinav Omprakash