|
|
Subscribe / Log in / New account

Racket: Lisp for learning

Did you know...?

LWN.net is a subscriber-supported publication; we rely on subscribers to keep the entire operation going. Please help out by buying a subscription and keeping LWN on the net.

By Jake Edge
August 6, 2019

Lisp is one of the oldest programming languages still in use today—Fortran is older by a year, but the Lisp community (or communities) seems to be the more dynamic of the two. In any case, the Lisp landscape has a lot of nooks and crannies to explore; I recently ran into a dialect that I had not encountered before: Racket. That may simply reflect ignorance on my part, but, while I was introduced to Lisp (too) many moons ago, I had not really paid it much mind until I sat in on a talk about Lisp at linux.conf.au earlier this year. Something about Racket caught my eye, so I did some poking around to see what it is all about.

The dynamism in the Lisp world also means that there are lots of projects, subprojects, dialects, descendants, and so on to keep straight. Lisp itself has split into three main dialects: Common Lisp, Scheme, and Clojure. Common Lisp and Scheme each have multiple implementations. Racket is based on Scheme; it was known as "PLT Scheme" (after the PLT organization behind the language) until version 5.0 was released in 2010.

Descended from Scheme

So Racket is a Scheme descendant, but not a Scheme implementation. It is described on its home page as a cross-platform, general-purpose language, but one with a focus on language-oriented programming. The Racket Manifesto goes even further down that path:

First, programming is about stating and solving problems, and this activity normally takes place in a context with its own language of discourse; good programmers ought to formulate this language as a programming language. Hence, Racket is a programming language for creating new programming languages.

And, in fact, there are already multiple languages defined for Racket, including a web-application language; a logic-based language similar to Prolog, datalog; Scribble for generating HTML and PDF documentation; and more. Racket, like Python, advertises itself as a "batteries included" language, with a standard library that contains many different useful modules, including for graphics and GUIs, networking, format parsing, left-pad, and so on; the Racket Documentation page has links to the ecosystem's extensive documentation.

Racket was created in part to further the educational aims of its developers, who are largely computer science professors and graduate students. The How to Design Programs textbook is based around Racket programming and its integrated development environment (IDE), but does not actually teach Racket itself. It starts with the Beginning Student Language (BSL) and moves on to various more advanced dialects; these languages are targeted at novice programmers and, in particular, ensuring that error diagnosis is usable by beginners. As a note in the preface puts it:

The teaching languages are implemented in Racket, a programming language we built for building programming languages. Racket has escaped from the lab into the real world, and it is a programming vehicle of choice in a variety of settings, from gaming to the control of telescope arrays. Although the teaching languages borrow elements from the Racket language, this book does not teach Racket. Then again, a student who has completed this book can easily move on to Racket.

DrRacket

The IDE is DrRacket, which provides an interactive read-eval-print loop (REPL) in the "interactions window" and an editor for programs in the "definitions window", as can be seen in the screen shot below. The definitions window is at the top (with the rocket and LWN penguin), half obscured by the help information, which has been locked in place. The interactions window is at the bottom; it shows an arrow in the upper right that leads to help text (which can be locked in place as was done above). Graphical elements are handled like any other data type; the Quick introduction provides a kind of overview of the language using graphics, stepping through the major features of the language (which are, unsurprisingly, Lisp-like). It works its way up through binding, functions, macros, and so on, ending up with a brief look at the object system in the guise of the GUI library.

[DrRacket]

That introduction uses the "#lang slideshow" dialect of Racket; in general, "#lang" is used in the definitions window to say which language is being used. #lang racket is the standard dialect, though "typed/racket", "racket/gui", "web-server/insta", "datalog", and many others can be specified there. As one would guess, DrRacket has helpful parenthesis-handling features, syntax highlighting, debugging tools, and more. It is geared toward newbies, but does not look to be too "dumbed down" for those with more experience.

All of the different languages and dialects of Racket are a bit confusing, at least for this (relative) newbie, but it gets even further complicated. There is a new version of Racket under development that sits atop Chez Scheme instead of the existing C-based version; it is known as "Racket on Chez Scheme" or just "Racket CS". It is meant to eventually become the standard Racket, in large part because it will make for a more maintainable code base, according to the original project announcement in 2017 and the January 2019 progress report. Racket CS will be largely compatible with Racket, but there will be exceptions (particularly for extensions that use the C API), so the existing Racket implementation will still be maintained.

All of that means that users will have a choice when installing Racket, starting with the upcoming 7.4 release. Racket CS will be available as a beta download when the new version comes out. For Linux users who want to try Racket out, it is available for most distributions (e.g. Racket 7.0 for Fedora 29); if the most recent release is desired, it is available in binary form via a shell script installer. The source code for Racket is on GitHub; it is available under the LGPLv3. Racket is also a member project of the Software Freedom Conservancy

Parting thoughts

Racket is a daunting project to dip into. As with any overview, this one barely scratches the surface of what Racket has to offer. For those looking for a Lisp-like language to explore, Racket looks like a good choice; the documentation, textbook, and multiple domain-specific tutorials means that there is a wealth of information to digest and apply. The textbook, in particular, looks like something I will try to find some time to dig further into; I may not have truly grokked Lisp the first time around, but Racket may provide another opportunity to do so.



(Log in to post comments)

Racket: Lisp for learning

Posted Aug 8, 2019 5:41 UTC (Thu) by pr1268 (subscriber, #24648) [Link]

I'm still kicking myself for never having learned lisp... All this Racket (pun intended) may change that.

As for Lisp and Fortran being "old"—I just read this today. First answer mentioned that

...NASA specified that his [the engineer who retired in 2015] replacement would have to know Fortran.

Just goes to show that these legacy languages refuse to die! :-)


Copyright © 2019, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds