dark mode light mode Search Menu
Search

Racket

Andre Mayer on Slideshare

Most of us know a few functions. We learn the addition function, the subtraction function, and then go on to learn multiplication and division functions. But what about rectangle? circle? star? In the Racket language, supplemented by the picturing programs library, these shapes are functions as well.

Racket is a fun programming language that builds logically off of the concepts of functions and variables as they are presented in mathematics. Just as the addition function accepts numbers and adds them up, the rectangle function accepts a length and a width, and draws a rectangle. However, in Racket, a rectangle is not only defined by its length and width, but also by its shading and color. There are two options for shading, “solid” and “outline”, and nearly 200 pre-defined of options for color. The code for a solid orange 105 x 60 rectangle (measured in pixels) appears as follows:

(rectangle 105 60 “solid” “orange”)

Each line of Racket code begins with a function, such as rectangle in the example above. The function name is followed by the parameters that Racket requires for that particular function. In the case of the rectangle function, these parameters are various data types that compose the domain of the function. In coding lingo, arguments such as solid, outline, red, purple, and so on are known as strings. Think of them as inputs from the keyboard strung together with a set of quotation marks. The range of the rectangle function is the output, and its data type is an image.

Much of the fun in learning Racket with Picturing Programs is that we get to begin using images as data types from the very first lesson. Your math teacher might be happy to know that while you learn to rotate, crop, overlay, and animate images, you are also improving your understanding of functions, variables, domain, and range. Perhaps equally valuable is that software engineers will be happy to know that you are learning excellent programming practices. By the end Chapter 5, beginning Racket programmers have learned documentation skills and can already design unit tests for each function they create.

This consistency with mathematics and the emphasis on excellent programming practices are two compelling features of the Racket language, particularly when learned through texts such as Picturing Programs (appropriate for middle school on up) or How to Design Programs (better suited for upper level high school through college). The language itself is a dialect of Lisp, used more in academia and research than in places such as Silicon Valley.

Experienced programmers might recognize the syntax from work or study they may have done with Scheme. In fact, Racket is a dialogue of Scheme; it is actually the new name given to PLT Scheme in 2010. It is a full spectrum programming language that can be used to create new dialects, build web-servers, research, or just have fun with while creating images and animations while learning excellent programming skills.

language-racket-screenshot
The Default Screen for the DrRacket Editor

To get started, install the DrRacket programming environment on a computer and download picturing programs. Once DrRacket is set up, as shown above, you’ll notice the window is split into upper and lower sections, the definition window and the interpreter respectively. In the definitions window, type the following and click Run (the green arrow button at top right of the screen):

(require picturing-programs)

Not much appears to happen, however requiring picturing programs enables you to access the functions included in the Picturing Programs library. In the interpreter window (bottom section of DrRacket), you can now try out a few lines of code such as those listed below:

>(+ 30 60)
> (* 2 3 10)
> (rectangle 70 100 “solid” “purple”)
> (star 80 “outline” “green”)
> (rhombus 100 30 “solid” “cyan”)
> (text “I can code” 60 “orange”)

Try various numbers and colors for the functions listed above to figure out what each argument controls. Next, you can combine, or nest, them. What do you think will happen when you type the following?:

>(+ (* 2 5) 9)
>(overlay (text “Racket” 40 “purple”) (circle 80 “solid” “orange”))

Try these out to see if you’re right!

What if you don’t want your coded creations to be limited to the functions that the Picturing Programs library provides? The definitions frame above the interpreter allows you to import your own images. You can use the define function to name them.

Ready to try it out? Prepare a couple images to experiment with; both a Google image search or your own creations work. Depending on your programming background, within 10-30 hours of practice working through Picturing Programs you’ll have an array of fun combinations of text, images, and numerical inputs and outputs, an understanding of best practices in software design, and possibly even a few animations.

If you are an educator that works with students in pre-algebra through advanced algebra, you might take a look at Bootstrap World, a curriculum created by a software engineer, turned middle school math teacher, turned curriculum designer, that uses Racket code to improve students’ understanding of algebra and coding by leading them through the creation of a video game.

Budding programmers can continue working their way through Racket texts and branching off with their own projects. If interested in heading in the direction of a language more commonly used in industry, they can apply what they have learned to the Pyret language, a transition between Racket and Python, or jump straight to Python, Ruby, JavaScript, or other heavily used programming languages.

Learn More

Racket and DrRacket IDE (free download)

https://racket-lang.org
https://racket-lang.org/download/
https://docs.racket-lang.org/drracket/
https://en.wikipedia.org/wiki/Racket_(programming_language)

The Pyret Language

https://www.pyret.org/

Picturing Programs

http://picturingprograms.com/

How to Design Programs

https://mitpress.mit.edu/books/how-design-programs

Bootstrap World

http://www.bootstrapworld.org/
http://www.bootstrapworld.org/materials/fall2015/tutorial/

WeScheme (cloud-based Racket programming environment)

http://www.wescheme.org/

Related Posts