Basic Lisp Techniques - David J. Cooper.pdf

(578 KB) Pobierz
103288898 UNPDF
Basic Lisp Techniques
David J. Cooper, Jr.
September 10, 2000
ii
0 Copyright c 2000, Franz Inc. and David J. Cooper, Jr.
Foreword 1
Computers, and the software applications that power them, permeate every facet of our daily lives.
From groceries to airline reservations to dental appointments, our reliance on technology is all-
encompassing.
And, we want more. Every day, our expectations of technology and software increase:
smaller cell phones that surf the net
better search engines that generate information we actually want
voice-activated laptops
cars that know exactly where to go
The list is endless. Unfortunately, there is not an endless supply of programmers and developers
to satisfy our insatiable appetites for new features and gadgets. \Cheap talent" to help complete
the \grunt work" of an application no longer exists. Further, the days of unlimited funding are over.
Investors want to see results, fast. Every day, hundreds of magazine and on-line articles focus on
the time and people resources needed to support future technological expectations.
Common Lisp (CL) is one of the few languages and development options that can meet these
challenges. Powerful, exible, changeable on the y | increasingly, CL is playing a leading role in
areas with complex problem-solving demands. Engineers in the elds of bioinformatics, scheduling,
data mining, document management, B2B, and E-commerce have all turned to CL to complete their
applications on time and within budget. But CL is no longer just appropriate for the most complex
problems. Applications of modest complexity, but with demanding needs for fast development cycles
and customization, are also ideal candidates for CL.
Other languages have tried to mimic CL, with limited success. Perl, Python, Java, C++, C# |
they all incorporate some of the features that give Lisp its power, but their implementations tend
to be brittle.
The purpose of this book is to showcase the features that make CL so much better than these
imitators, and to give you a \quick-start" guide for using Common Lisp as a development environ-
ment. If you are an experienced programmer in languages other than Lisp, this guide gives you all
the tools you need to begin writing Lisp applications. If you've had some exposure to Lisp in the
past, this guide will help refresh those memories and shed some new light on CL for you.
But be careful, Lisp can be addicting! This is why many Fortune 500 companies will use nothing
else on their 24/7, cutting-edge, mission-critical applications. After reading this book, trying our
software, and experiencing a 3 to 10 times increase in productivity, we believe you will feel the same
way.
1 this Foreword was authored by Franz Inc.
iii
iv
Contents
1 Introduction
1
1.1 The Past, Present, and Future of Common Lisp . . . . . . . . . . . . . . . . . . . . .
1
1.1.1 Lisp Yesterday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.1.2 Lisp Today . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.1.3 Lisp Tomorrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.2 Convergence of Hardware and Software . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.3 The CL Model of Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2 Operating a CL Development Environment 5
2.1 Installing a CL Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Running CL in a Shell Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1 Starting CL from a Terminal Window . . . . . . . . . . . . . . . . . . . . . . 6
2.2.2 Stopping CL from a Terminal Window . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Running CL inside a Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 A Note on Emacs and Text Editors . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.2 Emacs Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.3 Starting, Stopping, and Working With CL inside an Emacs Shell . . . . . . . 8
2.4 Running CL as a subprocess of Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4.1 Starting the CL subprocess within Emacs . . . . . . . . . . . . . . . . . . . . 9
2.4.2 Working with CL as an Emacs subprocess . . . . . . . . . . . . . . . . . . . . 10
2.4.3 Compiling and Loading a File from an Emacs buer . . . . . . . . . . . . . . 11
2.5 Integrated Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.6 The User Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.7 Using CL as a scripting language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.8 Debugging in CL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.8.1 Common debugger commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.8.2 Interpreted vs Compiled Code . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.8.3 Use of (break) and C-c to interrupt . . . . . . . . . . . . . . . . . . . . . . . . 14
2.8.4 Proling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.9 Developing Programs and Applications in CL . . . . . . . . . . . . . . . . . . . . . . 15
2.9.1 A Layered Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.9.2 Compiling and Loading your Project . . . . . . . . . . . . . . . . . . . . . . . 15
2.9.3 Creating an Application \Fasl" File . . . . . . . . . . . . . . . . . . . . . . . 16
2.9.4 Creating an Image File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.9.5 Building Runtime Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.9.6 Using an Application Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.10 Using CL with Other Languages and Environments . . . . . . . . . . . . . . . . . . . 17
2.10.1 Interfacing with the Operating System . . . . . . . . . . . . . . . . . . . . . . 17
2.10.2 Foreign Function Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
v
Zgłoś jeśli naruszono regulamin