Lecture 1, June 19

The lecture notes I post serve two purposes: to remind you of the topics we discussed and to provide any interesting code examples I did during lecture. I would describe these notes as an outline, not a summary, of what I talked about during lecture. You are not expected to be able to learn the material simply from examining these notes, nor is reading these notes a reasonable substitute for attending lecture.

Types

Simple Types

Number

There are many different subtypes of numbers. You won't have to know all of them, but you should be familiar with a few common ones. In particular, Integer, Exact-Rational, Real, and Complex are all types you should be familiar with.

Examples: 3, pi, 7/9, -8

Boolean

In contrast to the Number type, which may have infinitely many values, the Boolean type has only two values, true and false. These are represented by true or #t and false or #f in DrRacket.

Examples: true, false

String

The String type is used for representing text.

Examples: "Hello", "World", ""

Complex Types

Union

Union types are for expressions that can have different types. For example, if an expression could be either a string or a number, that expression has type (U String Number).

Function

Function types are how we describe the types that operations take as inputs and produce as outputs. We use the -> symbol to create function types from other types. An example would be something like (-> Number Number Number), which indicates a function that takes two numbers as inputs and produces a single number as output.

Common Operations

On Numbers

+, -, /, *, sqrt, sin, cos, expt, =, <, <=, >, >=, remainder, log, modulo

On Booleans

not, and, or

On Strings

string-length, string-append, string-ith, number->string, string->number

Using DrRacket

Prefix notation

Expressions are always built using prefix notation in DrRacket

Definitions

We can define variables using (define VAR EXPRESSION).

You can specify the type of a variable with (: VAR : TYPE). In this class you will always be expected to put a type declaration before every definition you write.

Other

Expression Trees

You can write a tree representation of any expression. These trees are evaluated from the bottom up.

Terminology

Truth Tables

A truth table is a way of expressing a boolean operation. You include one line for every possible set of inputs to the operation. On each line you list each of the inputs and the output of the operation.