Racket

This programming language is both easy to learn and teaches excellent coding form.

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.

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.

The Pyret Language

https://www.pyret.org/

Picturing Programs

http://picturingprograms.com/

How to Design Programs

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

WeScheme (cloud-based Racket programming environment)

http://www.wescheme.org/

Author

• Tim is an award-winning writer and technologist who enjoys teaching tech to non-technical people. He has many years experience with web sites and applications in business, technical, and creative roles. He and his wife have two kids, now teenagers, who are mad about video games.

Also In The April 2016 Issue

The iDTech summer camp recently posted 102 questions. Here are a few with links to the full list.

The choice of a first programming language can be overwhelming, from simple drag and drop to full languages.

10 steps you can take to improve your skills as a programmer.

REST is a standard way for software applications to work with each other to do things.

Blockchain software technology works as a distributed ledger to record what was done and when.

This online emulator lets you learn and try out a little of the Ruby programming language.

Here's a fun way to learn about telnet and watch the original Star Wars movie in ASCII format.

Believe it or not, computers and keyboards were not invented together.

Learn the basics of Go plus neat math details about Go and AlphaGo, the computer that beat a human playing Go.

If you were a wizard, wouldn't you want to know how to scale your spells for maximum effect?

This programming language is both easy to learn and teaches excellent coding form.

— John Johnson

Code Monster from Crunchzilla is a fun online emulator used to learn JavaScript.

A phone and tablet app exposes the invisible world of radio, phone, and satellite waves that connect our computers.

ASCII is a set of letters, numbers, and characters computers use to communicate accurately.

Links from the bottom of all the April 2016 articles, collected in one place for you to print, share, or bookmark.

Computing at School (CAS) provides resources and support for computer science teachers and parents.

Interesting stories about computer science, software programming, and technology for April 2016.

Interested but not ready to subscribe? Sign-up for our free monthly email newsletter with curated site content and a new issue email announcement that we send every two months.

No, thanks!