Skip to main content
Top

1998 | Book

Programming and Meta-Programming in Scheme

Author: Jon Pearce

Publisher: Springer New York

Book Series : Undergraduate Texts in Computer Science

insite
SEARCH

About this book

By now, Scheme is a well-established programming language and is finding increasing popularity in programming courses for undergraduates. Its expressive capabilities are matched by a simplicity of language and ease-of-use which have made its adherents disciples! This textbook provides a comprehensive first course in Scheme and covers all of its major features: abstraction, functional programming, data types, recursion, and semantic programming. Although the primary goal of this text is to teach students to program in Scheme, it will be suitable for any student studying a general programming principles course. Each chapter is divided into three sections: core, appendix , and problems. Most essential topics are covered in the core section, but it is assumed that most students will read the appendices and solve most of the problems. (Nearly all of the problems require students to write short Scheme procedures.) As well as providing a thorough grounding in Scheme, the author discusses in depth different programming paradigms. An important theme throughout is that of "meta-programming": the perspective that programs themselves can be treated as data, and hence can be analyzed and modified as objects. This provides insight into topics such as type-checking and overloading which might otherwise be missed.

Table of Contents

Frontmatter
Introduction
Abstract
Soon after the first commercial computers appeared in the early 1950s people began seeing analogies between computers and brains, and they wondered if computers could exhibit human-like intelligent behavior. Could computers be programmed to reason, learn, and plan? Could computers solve problems they weren’t explicitly programmed to solve?
Jon Pearce
1. Expressions and Values
Abstract
A Scheme interpreter is a primitive version of Deep Thought, the enigmatic supercomputer in Douglas Adams’ book. We type a question on a keyboard, the Scheme interpreter displays the answer on a screen, and then asks for another question.
Jon Pearce
2. Procedures
Abstract
Although Scheme provides quite a few procedures, there are many more it does not provide. This isn’t a problem because programmers can define their own procedures using lambda expressions. The format of a lambda expression is:
$$LAMBDA ::= (lambda PARAMETERS BODY)$$
Jon Pearce
3. Evaluation Control and Recursion
Abstract
In the last chapter we described the four-step evaluation procedure used by Scheme to evaluate procedure applications:
  • Evaluate operator.
  • Evaluate operands to produce arguments.
  • Replace parameters by arguments in the body.
  • Evaluate body.
Jon Pearce
4. Data Control
Abstract
The theme of this chapter is controlling access to procedures and data by either hiding them or hiding information about how they are represented. In both cases access is restricted to certain privileged procedures. This may sound like censorship, but inviting procedures written by others to access one’s own data and procedures invites potential misuse and unwanted alterations. We can formalize our theme as the information hiding principle:
Information should only be made available on a need-to-know basis.
Jon Pearce
5. Iteration
Abstract
The systems Capra is referring to are so ubiquitous that any definition would sound hopelessly vague (we’ll try anyway). Electromechanical systems range from computer chips and vending machines to space shuttles and ocean liners, while biological systems range from viruses and amoebas to whales, brains, and redwoods. Some organisms form complex social systems such as ecosystems, beehives, ant hills, universities, corporations, armies, even nations. There are legal systems, economic systems, mathematical systems, problem-solving systems, solar systems, weather systems, hardware systems, and software systems. The whole universe is a system.
Jon Pearce
6. Recursive Domains
Abstract
Like procedures, domains can have recursive definitions. For example, the VALUE and EXPRESSION domains defined in Chapter One were recursive. The VALUE domain onsisted of simple and composite values:
$$VALUE:: = SIMPLE|COMPOSITE$$
Jon Pearce
7. Variables
Abstract
In addition to the Global Environment, the Scheme evaluator maintains another structure called the global store. A store is an array of data containers called cells. A value that can be contained in a cell is called a storable value. Not all values are storable; for now we will identify storable values with simple values (numbers, Booles, chars, symbols, etc.) and the empty list:
$$STORABLE:: = ()|SIMPLE$$
Jon Pearce
8. Expressions as Values
Abstract
Sick of philosophical debates deteriorating into shouting matches, the philosopher- mathematician Gottfried Leibniz (1646–1716) wondered why philosophy couldn’t be more objective, like science and mathematics. He then hit upon an idea that would inspire thinkers for centuries to follow: What if philosophical propositions could be proved or refuted by procedures that manipulated them as pure symbolic data:
If we had it we should be able to reason in metaphysics and morals in much the same way as geometry and analysis. If controversies were to arise, there would be no more need of disputation between two philosophers than between two accountants. For it would suffice to take their pencils in their hands, to sit down to their slates, and to say to each other (with a friend as witness, if they liked): Let us calculate.
This was an early articulation of the expressions-as-data idea. It eventually led to mathematical logic, stored program computers, artificial intelegence, and meta-programming.
Jon Pearce
Backmatter
Metadata
Title
Programming and Meta-Programming in Scheme
Author
Jon Pearce
Copyright Year
1998
Publisher
Springer New York
Electronic ISBN
978-1-4612-1682-7
Print ISBN
978-1-4612-7243-4
DOI
https://doi.org/10.1007/978-1-4612-1682-7