Class 05: Symbols and Lists

Reading: Symbols and lists. Lab: Symbols and Lists. Back to Starting Scheme. On to Numbers.

Held Monday, January 29, 2001

Summary

Today we consider two of Scheme's most important types of data: symbolic values and lists.

Assignments

Notes

• Are there any questions on the reading on lists?
• Quiz (paper).
• Are there any questions on homework 1?
• I hope to send out information on combining logical and physical formatting this evening. (It depends a lot on how the weather goes.)

Overview

• A short history of Scheme
• Symbolic values
• Lists
• Lab

A Short History of Scheme

• Scheme is a variant of Lisp (the List processing language).
• Lisp is one of the oldest high-level programming languages in active use
• It's from about the time of the invention of Cobol and only a few years after the invention of Fortran.
• John McCarthy (of MIT and then Stanford) designed Lisp to provide a language for programming in artificial intelligence.
• At the time, many people believed that intelligence was grounded in symbolic processing.
• Lisp added many things to languages of the day:
• Symbolic values
• Dynamic lists as built-in data structures
• Automatic memory managment for those built-in data structures
• Functions as values (we'll return to this in a few weeks)
• In later reflection, McCarthy indicated that some of these things were just luck. For example, the `lambda` that you'll learn about soon was just a "hmmm ... that sounds interesting, I'll put it in" fluke.
• Scheme was designed in the early 1980's (or maybe late 1970's) as a variant of Lisp more appropriate for teaching computer science (and doing many other things; it's more elegant).
• Scheme has a slightly clearer semantics than Lisp (and a formal semantics, which is important).
• But, at least for 151, you're doing Lisp-like programming.

Symbols

• A key aspect of Scheme (see above).
• The easiest way to build a symbol is with the quote operation.
```> 'a
a
> a
reference to undefined identifier: a
> (quote a)
a
```
• Useful when you want to represent something atomically (as an idea that can't be pulled apart).

Lists

• The core of Scheme.
• Dynamic: Lists can "grow" and "shrink"
• Or at least you can build larger or smaller lists from other lists.
• The simplest list: the empty list is `null` or `()`.
• You extend a list at the front (or, more precisely, build a new list) with
```(cons thing-for-the-front rest-of-the-list)
```
• For example,
```> (cons 'a null)
(a)
> (cons 'b (cons 'a null))
(b a)
```
• You can also create lists with `list`.
```> (list 'a 'b 'c)
(a b c)
```
• You extract parts of lists with three operations (we'll reflect on the naming later in the semester):
• `car`: get the initial element of the list.
• `cdr`: get all but the initial element of the list.
• `list-ref`: get the ith element of the list.
• One disadvantage: Scheme lists look a lot like procedure applications, so it's sometimes hard for beginning programmers to tell what's going on.
• You can always tell by context, but it takes some time to get used to contexts.

Lab

• Do the lists lab.
• We'll try to use the last five minutes of class to reflect.
• You may have to complete the remainder of the lab on your own.

History

Friday, 12 January 2001

• Created generic outline format for class.

Back to Starting Scheme. On to Numbers.

Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Wed May 5 12:14:47 2004.
This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/outline.05.html`.