O'Reilly logo

Realm of Racket by Matthias Felleisen, Eight Students of Northeastern University, David Van Horn, Conrad Barski M.D.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. (The Values of Loops)

#|

Lists are a central data type in Racket. We started off manipulating them manually. Then we learned about lambda and functions like map and foldl. Now we will introduce a third and even more powerful way of managing lists: for loops.

|#

9.1 FOR Loops

If you have taken a run-of-the-mill course on programming or read one of those standard introductory books, you know about for loops. Racketeers have a special relationship with loops, and therefore Racket has many kinds of for loops. Each has its own uses and purposes. Anything you can do with map, foldl, foldr, filter, andmap, ormap, and so on, you can do with for loops.

The basic for loop looks and acts like the one you may already know:

> (for ([i '(1 2 3 4 5)]) (display ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required