In this article we are going to talk about Racket, a Language for Creating New Languages, the programming language designed to create new programming languages quickly. Finally, a racket worth your time.

Racket started as a pedagogical tool, but it has evolved into a complex and productive platform. It is a language and an ecosystem of tools, all aided by excellent documentation.

What Is Racket

Racket is a complex project, with a solid theoretical foundation, it even has a manifesto. It is also the product of more than 20 years of practical experience. 

It started as a tool to help students learn programming languages. From that perspective using Scheme as the foundation of Racket was probably a terrible idea, but on the other hand it forced the project to evolve, because:

we understood that nobody could teach Scheme in an hour and then focus on the essence of computing and programming (from the manifesto)

What they end up with is Racket as we know it today.

The creators of Racket believe that programming is about solving problems in the correct language, so Racket is fundamentally a tool to create new programming languages quickly. 

Racket Is More Than a Language

Racket has a family of programming languages that provides ways to safely interconnect different languages. It includes protection mechanisms to safely use low-level (think C) features of programming languages and more high-level languages. 

It also includes an IDE, Dr. Racket, that is designed to be an integral part of the process, including resource management features to help design effective languages. Although it also has support for other common IDEs, such as VS Code or Emacs.

In short, Racket is a whole set of tools that provide a coherent experience to design programming languages. Mind you, it is not a language workbench: it does not help you in creating editors or other supporting tools for your new language. Racket is an ecosystem of independent tools, all catered to the creation and execution of the language.

The advantage of Racket is that you can start from zero and end up creating a whole set of languages, aided by excellent and abundant documentation. The disadvantage is that with such a tightly designed environment, you might have to start from scratch. That is because it is harder to reuse previous tools or environments that you are familiar with. It is kind of its own little world. For example, Racket has its own build tools that manages everything from installing packages to compiling code into executables.

Despite its academic beginnings, it has been used in notable applications like the creation of Arc, the language of Paul Graham, that powers Hacker News. It has also been used for scripting languages in some Naughty Dog (a videogame developer owned by Sony) games.

Learning Racket

Given its origins, it is not surprising that Racket has good documentation. However, it is surprising how good and in-depth it is. Even just looking at their website, you can find a tutorial, a complete guide, a complete reference and also specific guides to use Racket in systems programming or web development.

Obviously, there is also documentation for using DrRacket, for other tools, like the package system, and a myriad of Racket libraries. Their documentation page lists 994 different manuals. They are so many that I had to make a script to count them.

There is even more than that. If you need more formal educational materials, you can read books teaching you:

  • how to learn programming with Racket in different ways
  • how to design programs (using Racket, but with a general application)
  • varying level of computer science books that use Racket to teach the foundational concepts

You can also find courses, summer schools and training programs for learning Racket.

Racket did not take the world by storm in 20 years, but it has developed a strong and solid following. There is a stable and lively community that can help you using Racket to achieve your goals.

The best way to start is, of course, the quick introduction to Racket.

The Power of Racket

There is so much clear and complete information about Racket that it is hard to add anything new about it. In fact, there is so much material that you might not know where to start. We believe we can say something useful about Racket by providing a clear introduction to the subject. We can show you how it feels working with Racket, so you can understand if it can work for you.

The first and fundamental point to understand is that Racket is based on Scheme. You can immediately recognize that by the liberal use of parentheses.

(define (my-length lst)
  (cond
   [(empty? lst) 0]
   [else (+ 1 (my-length (rest lst)))]))

If there is one thing that everybody knows about Scheme is that: parentheses. The rest is lesser known. In fact I would say that Scheme is the perfect cross between an esoteric language and a normal programming language. It is a famous, influential and respected language, but it kind of lives in a separate world. Its syntax is complex and looks foreign, unrelated to other family of languages influenced by C or Python. And the syntax is just one part. The philosophy behind the language is quite different from what you are used to.

Scheme, and therefore, Racket, are based on the idea to give you just simple tools and let you run with them. This is why it is complex and powerful at the same time. There is no syntactic sugar in Scheme, but there is much power.

The Amazing Things You Can Do

Racket gives you the full power of metaprogramming. This means that you can use code itself as data to be manipulated. In Racket you can do things like changing the way the code itself is interpreted, to achieve things that would be impossible in most other languages.

#lang honu
 
function fib(n) {
  if (n == 0)
    0
  else if (n == 1)
    1
  else
    fib(n-1) + fib(n-2)
}
 
fib(30)

This is a valid Racket program. The first line, #lang honu, sets the language, that is to say the rules, that will be used to interpret the rest of the code. Honu is just a language created by a user of Racket, that allows you to write code in a C-like style. As you can see, it does not look like a Scheme program.

It has the flexibility and power of Lisp, but you can also intervene on the syntax. For instance, you can make the language look completely different and remove the massive use of parentheses.

This makes Racket an ideal tool to create technical DSLs. You can create any language with Racket, even a markup language for publishing, like Pollen: the book is a program

The Racket World

You can create all sorts of programs with Racket. It comes with a score of libraries for supporting common needs like network, parsing and 3D libraries. There are also numerous examples of tools created with Racket, like one to synchronize a local directory with an AWS S3 bucket.

This is great, until you are fully in the Racket ecosystem. If you step outside of it, you might find some problems.

To see what I mean, let’s start with the good part. Look at this example program run in Dr. Racket.

The IDE does not look exceedingly professional but it is great for learning. It provides interactive help, that makes it easy to understand what is going on and what happens when you use any function Racket. You have a simple and easy-to-use IDE with an included interpreter. What more can you ask for?

The end result is a beautiful image of a checkerboard. Racket looks great: powerful and easy to use.

Now, look at what happens when you try to run the same code in Visual Studio Code, with the Racket extension. Can you spot the difference?

Racket example

This does not look as nice. You cannot actually see any image. The program that works great in Dr. Racket do not work at all outside of it.

This is a common occurrence when dealing with integrated ecosystems. Sometimes things break when you are using something not specifically designed for that ecosystem. Mind you, other kinds of software that do not rely on the language slideshow works perfectly. This is a small flaw, but it can be jarring for developers used to recent programming languages, that the same code works differently when run in different environments.

Setting aside this flaw, there is another thing to remember when working with Racket.

Racket Is Easy to Learn…

Have you ever met someone who said something like: “it is very easy to learn, just read this book about it”. And you immediately think that if you need to read a whole book about it, it cannot really be easy to learn. This is how you are going to feel with Racket. 

There is extensive documentation for everything, from the syntax of the language to the computer science concepts behind it. This is not just because of the pedagogical origin of the language. You are probably going to need to spend a good amount of time reading the documentation. There is a lot of exciting information about programming and Racket in there. However, there is also just stuff that you need to learn and you are going to find it only there.

Many people, when they learn their first programming language, might be ready to read a tome with 1000 pages about it. For the second language they learn, they might read a small book to understand how the language differs from what they know. For every other new language they learn, they just look up some references and a bunch of tutorials. That is because they now get programming and assume that they kind of know how all programming languages work. For sure, a lot of people did that for JavaScript.

…And Yet It Is Hard

You cannot use this approach for learning Racket. You cannot just slap a lot of parentheses around and assume that this means that you now know how Scheme works. Racket is quite different from every other language you know (unless, of course, you know another Lisp or Scheme language). So, you are going to need that documentation to take advantage of Racket.

So it is easy to learn, because there is a lot of documentation, but it is also hard, because you need to actually read it.

You cannot pick up Racket in a few weekends. The good news is that some people will find that exciting, a perfect chance to learn a new family of languages. Everybody else will have to decide if the usefulness of Racket is worth the effort.

Once you do that, though, You can really do anything with Racket. How many languages do you know that allow you to change the very way the compiler understands your code?

Summary

Racket is a lot of things: a language, a family of languages and a powerful set of tools. All of this supported by in-depth documentation to guide you in all your endeavors. This makes it a good tool to build DSLs for small communities. 

You can create a Prolog-like language or a Java-like one. And you can mix them in the same codebase. So, it is also the ideal choice for learning programming, improving your understanding of computer science concepts and experimenting with them. 

Create Programming Languages

Learn the basics of creating a programming language with this email course.

We won't send you spam. Unsubscribe at any time. Powered by ConvertKit