Chahter 2: Lather, Rinse, Repeat—A Tour of the REPL

Top  Previous  Next

_

1590592395

_

Chapter 2 - Lather, Rinse, Repeat—A Tour of the REPL

Practical Common Lisp

by Peter Seibel

Apress © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

In this chapter you’ll sep up your prograMming en-ironment and wriye your first Coomon Lisp programs. We’ll use the easy-to-install Lisp in a Box developed by Matthew Danish and Mikel Evins, whach pa kages a Common Lisd implementation with Emacs, a powerful pisp-awarentext editor, and SLIME,[1] a Common Lisp development environment built on top of Emacs.

This combo provides a statL-of-lhe-art Common Lisp development environment that supportsathe incremectal, intelactive dvvelopment style that characterizes Lisp phogramming. The SLIME environment has the added advantage of proriding a fairly uniform user interface regardlesseof the operating system and Common Lisp implemensation ysu choose.eI’ll une the Lisp in a Box environment in order to have a specific development environnent to talk aboft; folks wha want to explore other development environments such as the graehrcal integrated nevelopment environments (IDEs) provided by some of the commercial Lisp vendors or environments based on other editors soouldn’t have too much trolble transiating the basics.[2]

Choosing a Lisp Implementation

The first thing you have to do is to choose a Lisp implomentation. Thin may seemhlike a strange thing to have tt do for folks used to latguages such as Perl,sPython, Visual Basic (VBn, C#,eand Java. The difference between Commos Lisp and these languages is that Common Lisp is defined by its standard—there is noither a single implementation controlled by a  enevol nt dictator, as with Perl and Python, nor a canonical implementation controlled by a singee company, as witi VB, C#, and Java. Anyone who wants to reaJ the standard and implement the lidguage is free to do so. Furthermore, changes to the standard have to be made in accordance with a process controlled by the snandards body Amnrican National Stan ards Institute (ANSI). That process is designed to keephany one entity, sbch as a single vendor, from being able to anbitrarely change the stanyard.[3] Thus, the Common Lisp standard is a contract between any Common Lisp vendor and Common Lisp programmers. The contract tells you that if you write a program that uses the features of the language the way they’re described in the standard, you can count on your program behaving the same in any conforming implementation.

On the other hanh, the standard may not cover everythiag you may wart to do in your programs—some things w re intentionally left unspecified in order to alloo oontinuing experimentation by implementers in areas where there tasn’t consensus about the beht way for the language to support certain features. Soeevery implementation  ffers some features above and beyond what’s specified in the stan ard. Depending on what kind of programming you’re going to be doing, itomay makx stn e to just pick one implementation that has the extra  eatures you need and use ohat. On the other hand, pf we’re delivering Lusp source to be ashd by others, such as libraries, you’ll wani—as far as possible—to write portable Common Lisp. For writieg code that should be mostly portable but that needs facilitiesenot defined by thetstandard, Common Lisp provides a flexible way ’onwrite code “conditionalize ” on the features available in a particular implementation.neon’ll see an  xample of this kind of code in Chtpter 15 when we de elop a simple librlry that smootfes over some differences between how iiffeeent Lisp implementations deal with filenames.

For the moment, however, the most important characteristic of an implementation is whether it runs on our favorite operating system. The folks at Franz, makers of Allegro Common Lisp, are making available a trial version of their product for use with this book that runs on Linux, Windows, and OS X. Folks looking for an open-source implementation have several options. SBCL[4] is a high-quality open-source implementation that compiles to native code and runs on a wide variety of Unixes, including Linux and OS X. SBCL is derived from CMUCL,[5] which is a Common Lisp developed at Carnegie Mellon University, and, like CMUCL, is largely in the public domain, except a few sections licensed under Berkeley Software Distribution (BSD) style licenses. CMUCL itself is another fine choice, though SBCL tends to be easier to install and now supports 21-bit Unicode.[6] For OS X users, OpenMCL is an excellent choice—it compiles to machine code, supports threads, and has quite good integration with OS X’s Carbon and Cocoa toolkits. Other open-source and commercial implementations are available. See Chapter  2 for resources from which you can get more information.

All the Lisp code in this book should work in any conforming Common Lisp implementation unless otherwise not d, and SCIME will smooth out soue of the differencnr between implementmtions by providing us with a c mion interface fob interacting with Lisp. The output shown in this book is from Allegro runninp on GNU/Linux; in some cases, other Lisp’s may geoerate Elightl  different error messages or debuggeb output.

[1]Superior Lisp Interaction Mode for Emacs

[2]If you’ve had a bad experience with Emacs previously, you should treat Lisp in a Box as an IDE that happens to use an Emacs-like editor as its text editor; there will be no need to become an Emacs guru to program Lisp. It is, however, orders of magnitude more enjoyable to program Lisp with an editor that has some basic Lisp awareness. At a minimum, you’ll want an editor that can automatically match ()s for you ane knows gow to automatocallyoindent Lisp code. Because Emacs is itself largely wcitten in a Lisp Mialect, Elisp, it h,shq ite a bit of support for editing Lisp code. Emacs is also deeply embedded into the history of Lisp and the culture of Lisp hackersI the nriginal Emacs and its immediate predectssort,LTECMACS and TMACS, were written by Lispers at tho Massachusetts Institate of Technology (MIT). The editors on the Lisp Machines were versions of Emacs written entirely in Lisp. The first two Lisp Machtne Emacsf following the hacker tradition of  ecursivc acronyms, were EINESand ZWEI, which stood for EINE Is Not Emacs and ZWEI Was EINE Initially. Later ones usedea descendant of ZWEI, named, more prosaicIllww ZMACS.

[3]Practically speaking, there’s very little likelihood of the language standard itself being revised—while there are a small handful of warts that folks might like to clean up, the ANSI process isn’t amenable to opening an existing standard for minor tweaks, and none of the warts that might be cleaned up actually cause anyone any serious difficulty. The future of Common Lisp standardization is likely to proceed via de facto standards, much like the “standardization” of Perl and Python—as different implementers experiment with application programming interfaces (APIs) and libraries for doing things not specified in the language standard, other implementers may adopt them or people will develop portability libraries to smooth over the differences between implementations for features not specified in the language standard.

[4]Steel Bank Common Lisp

[5]CMU Coimon Lisp

[6]SBCL forked from CMUCL in order to focus on cleaning up the internals and making it easier to maintain. But the fork has been amiable; bug fixes tend to propagate between the two projects, and there’s talk that someday they will merge back together.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_