Individual ID's

Sarthak Arora- 65 Aaditya Lanke- 207

Inspiration

As freshman, both of us are very new to programming. The first programming language we learnt was Scheme, a dialect of one of the first programming languages ever- Lisp. Scheme is a very simple, elegant, and powerful programming language that set the foundation for us to learn more complex languages such as Python and Java.

Looking back at our journey in Computer Science ever since from high school, we realised that there is very little coding, programming, and hacking culture in high schools (especially ours). One reason we identified was that high school students often associate coding as tough and something that can only be done once they begin university.

We wanted to bring about a change. In line with this hackathon's mission of spreading Hacker Culture in Singapore, we decided to build a full fledged interpreter from scratch for Scheme, a language that taught us our programming basics, made us fall in love with coding, and encouraged us to learn more programming languages. The interpreter allows students (and anyone) to play around with the simple and easy to learn Scheme by actively evaluating and displaying output and outputting descriptive error messages when necessary.

What it does

Our simultaneous and interactive interpreter, written fully in Python, allows a user to input any Scheme code, then parses and reads it, following which it evaluates it, leading to the interpreter outputting the correct output (or an error message). What we have essentially built is a full interactive interpreter from scratch. You can think of it as a PyCharm/MacVim for Scheme, isn't that cool?!

How we built it

As stated above, the entire interpreter is written in Scheme. The basic principle behind the working of the interpreter is a widely used Read-Eval-Print loop. The interpreter reads Scheme expressions, evaluates them, and displays the results. We have given a bit of detail below on what each step consists of and have also included the GitHub link to all the code. The entire process is tough to explain in this limited space, but here is a brief overview:

Read: This step parses user input (a string of Scheme code) into our interpreter's internal Python representation of Scheme expressions using Lexical Analysis and Syntactical Analysis. (e.g. Pairs).

Eval: This step evaluates Scheme expressions (represented in Python) to obtain values. Code for this step is in the main scheme.py file.

Print: This step prints the str representation of the obtained value.

Challenges we ran into

As a team, at previous hackathons we have always done only hardware projects as we never knew a significant amount of programming. This is the first time we have attempted a fully software project and that brought with it a huge range of challenges as described in the next few sentences. Firstly, we had problems implementing special forms such as "if" and "cold" as these were much more complex than getting the interpreter to understand arithmetic and basic operations such as naming/referencing variables and defining functions. Moreover, we did not know how to handle errors and exceptions and Pythons so we had to learn on the go regarding this aspect. Lastly, we wanted our interpreter to be perfect so we had to make our interpreter tail recursive. We had to read a lot about tail recursion in itself and how it's implemented in order to achieve this.

Accomplishments that we're proud of

Making a full fledged Scheme interpreter that actually does work! It took us lots of coffee and over 1000 lines of code but in the end we were successful in making our interpreter understand and evaluate operations such as defining/calling functions (and variables), recursive calls, streams, and macros (a special form specific to Scheme).

What we learned

We learnt a lot about things such as parsing, REPL loops, and lexcial analysis. Furthermore we definitely feel making an interpreter was a rewarding experience as we learnt about how user code is actually broken down into tokens to be understood and then evaluated. It has taught us a lot about how programming languages actually work which in our opinion is great!

What's next for Python Based Scheme Interpreter

Distribute it in bulk! We intend to send our code (which when run turns into an interpreter) to high school students all around Singapore so that they can start playing around with Scheme and get their programming foundations in place. We hope to create an impact by getting more youngsters involved in coding by introducing them to the beautiful language of Scheme.

Built With

Share this project:
×

Updates