Racket Programming

Warning: Racket programming is addictive. Not suitable for single guys living away from their Moms

Matthew Flat in a Racket Conference (2013) began his talk by asking “why are we here?” At first the audience thought here meant RacketCon. But he clarified “Why are we here in this universe?” Then he went on to state something along the lines of “The purpose of life is to develop a new programming language.” Obviously Racket is the best language for such purposes… obviously! Jokes aside , just why is Racket important?

Since the dawn of modern computing (1940’s) people have tried to cope with complexity. Macros and subroutines were the fist attempts to address this issue. Over the years we have come up with many solutions. Structured programming, functional programming and object oriented programming are all attempts to deal with complexity. In recent years object decomposition has almost completely replaced functional decomposition and that’s a shame, although languages like ‘Go’ go the other way and encourage a functional style. My experience with working with a large application that uses C++/C#/C has been that we have missed the woods for the trees. A simple task hops through so many virtual functions that by the time I get to where the task is actually executed I have lost track of the purpose of the task. A functional approach would have made it easier but old habits die hard. However the tasks are sometimes so complex that even in a functional style the code would run to so many pages that we will find it difficult to see what is going on. This is where Domain Specific Languages (DSL) come. We need to be able to come up with a DSL at short notice.

At one time writing a Pascal compiler was considered a six month project. While a good Pascal compiler would still take that much time, we don’t need a full fledged Turing complete language every time we design our DSL. This is where a language like Racket (child of Scheme child of Lisp) or ML and its derivatives come int use. Implementing a DSL that blends with Racket is not difficult. What is difficult is designing the language. The aim of the DSL should be to capture the concepts in such a way that we can understand what we have done.

Attending the Coursera course in Programming Langauges, I came to learn Racket. At first I hated those brackets, brackets and brackets. Then I became enamored and tried to solve some simple applications like Sudoku and BrainVita in a functional programming language, F#. But when I compared the code with C++ I found that C++ code was almost as small, if I ignore the lines containing just ‘{‘ or ‘}’. So the main advantage of Racket/Scheme/Lisp is not so much for specific problems but for a class of problems. Consider the case of a simple circuit consisting of resisters and a DC voltage. It is no too difficult to write some simultaneous linear equations SLE to compute the current passing through each circuit. In fact it used to be done manually for each circuit. With a language like Racket we can represent a circuit as Racket program and get racket to generate the set of SLE to solve a circuit. The same representation can then be used to draw the circuit using say TEX, AutoCAD or PDF. Thus a program has become data. If the same circuit is replicated many times then the program can be turned into a macro. Many such macros can then then be put together to solve larger circuits.

Another example is organic chemistry where we can describe one amino acid in terms of others. Or, we could replace one carbon atom with a free radical of equivalent valency. The advantage of one textual representation is that it can be used for many purposes. It can be reused with just-the-same-as-except-that pattern. Thus we move to a higher level programming where we can capture the knowledge in the form of programs that can be verified by experts.

Initially all those brackets seem intimidating not to mention meaningless keywords like car and cdr. But after the initial difficulties it seems so natural to think in terms of recursive functions that I would suggest that novice programmers including school children learn Racket as their first programming language.

About The Sunday Programmer

Joe is an experienced C++/C# developer on Windows. Currently looking out for an opening in C/C++ on Windows or Linux.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

1 Response to Racket Programming

  1. Donnell says:

    Very informative article, i am regular reader of your website.
    I noticed that your site is outranked by many other blogs in google’s search results.
    You deserve to be in top ten. I know what can help you, search
    in google for:
    Omond’s tips outsource the work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s