akumar.xyz

I Made a Programming Language

Jul 08, 2020

Dear reader, I’m going to be honest with you. You just got pranked. EPIC STYLE! *Dabs* 😎

The title is clickbait, but please do keep reading. You may find some interesting things.

A Domain Specific Language (DSL) is a specialized language designed to solve a very specific problem. Some examples might include

That is to say, the purpose of a DSL is to do one thing, and do it well. *Happy UNIX noises XD*

I had some code lying around in my computer that uses a greedy approach to minimize cashflow in settling debts within a closed system. Think Splitwise or Settle Up. I had been looking forward to dip my toes into meta-programming wizardry for a while now, and so, I wrapped that around a parser (surprisingly easy to implement) to create setl.

Setl :-

Setl is an imperative DSL who’s only purpose is to keep track of all the shared expenses in a closed system, and calculate the “settlements”.

This how you would add a shared expense in setl:

Foo: 100 @ Meal

OR

Foo:100, Bar:50 @ Meal

The idea is that users record all the expenses in a shared text file, using a very simple, very intuitive syntax. A tool will later parse the text file and do the calculating.

Refer to the documentation if you want to learn more.

In fewer than 500 lines of python code, setl can handle a surprising number of edge cases. No hanky-panky apps, user authentication, etc. Text STDIN and text STDOUT. The way gods intended it.

Very cool. 💪🏼❄️

This may possibly come in handy a few times if I survive the present apocalypse.

Now do I expect setl to gobble up Splitwise and Settle Up’s market share? Why yes ofcourse! Using bloat GUI “apps” is.. pfft.. CRINGE!

/s

However, here is the point I am trying to make. The ability to build DSL can potentially be a very handy tool in a developer’s toolkit. Especially for an application that is not consumer facing. Also, a fairly simply DSL can solve a fairly complex UI problem (provided it is designed well). If you want to learn how to build a DSL, do not use setl as a reference. That code reflects poorly on my skills as a code monkey.

There are 3 ways to implement a DSL.

Allow me to direct you to some further reading.

Further Reading.

More Further Reading.

Have a nice day!

- Adithya Kumar

Tags: programming, technology, misc