Brevity Guild Micro Fighter

Lisp Dialect

Arc Lisp (indirectly available in Common Lisp using custom macros)

image with no caption

Synopsis

Lisp allows you to write code that is incredibly concise but doesn’t look like your cat walked over your keyboard. (I’m looking at you, Perl!) This is possible because of the various features we’ve already mentioned, such as macros, functional programming, and Lisp’s dynamic typing system.

There is one Lisp dialect, however, that takes this idea to the extreme: Arc. In fact, code brevity is the primary design goal for this language. Paul Graham, the designer of Arc, analyzed large amounts of computer code in an attempt to figure out which primitive commands are needed to write code that is as concise as possible, while keeping the code readable.

How It Kills Bugs

With Arc, the goal is to write programs that are short. It is designed to let you say what you want to say in the most concise way possible, leaving no place for bugs to hide.

Example A-9. Example

 (accum a
   (for n 1 1000
        (unless (some [is 0 (mod n _)] (range 2 (- n 1)))
            a.n)))

Note

This example is in the Arc Lisp dialect and won’t run in Common Lisp.

Explanation

This example creates a list of all prime numbers between 1 and 1000, using the naïve method of checking for smaller numbers that divide evenly into the current loop value.

The accum function creates a local function named a, which is used to collect any primes that are found . We iterate through the integers with a for loop , checking for smaller numbers that divide evenly into the current value of i . If none are are found, i is added to the list of primes , by calling the function a with this new number. The brackets, [ ], are a shortcut for creating a lambda function with one parameter, which is accessed with the underscore character.

Weakness

Finding an optimally concise set of commands is difficult. With too many commands available, your code can become hard to understand, since it’s difficult to remember what each function does. With too few commands, programs can get too bulky. Arc Lisp tries to find a happy medium, although there’s still room for alternative language designs optimized for code brevity.

Chapter 16 demonstrates how to use macros to make your code concise, and many other examples of Lisp’s powers of brevity are shown in the chapters following that discussion.

image with no caption
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.60.249