Cover by Conrad Barski M.D.

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 10. Looping with the loop Command

The loop and format commands are powerful and hacker-friendly. Though most of the functionality they offer is available elsewhere in the Lisp language, these highly specialized commands are worth learning if you like terse code. We’ll look at loop in this chapter. The next chapter covers format.

The loop Macro

Any type of looping you would ever want to do inside a computer program can be accomplished with the loop macro. Here’s a simple example:

> (loop for i
        below 5
        sum i)
10

This code adds together the natural numbers below 5, like this:

0 + 1 + 2 + 3 + 4 = 10

You can see that this loop command doesn’t work in the way a proper Lisp command should. First of all, it’s parenthetically challenged. Never before ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required