Download presentation
Presentation is loading. Please wait.
1
Procedural versus Functional Programming
Is there a “mechanical” process that can determine whether any mathematical statement is true or false? (1928) Remember this idea: a mathematical statement can be either true or false. David Hilbert I formulated a model of a machine capable of general computation. I can use it to prove that there is no such process! (1935-6) Alonzo Church I proved that already! ( ) Alan Turing
2
Procedural versus Functional Programming
Turing and Church independently formulated two very different ways of describing computation: Turing’s: the Turing machine. Church’s: the Lambda Calculus. A Turing machine is an embodiment of the procedural style of programming: Do this. Then do this. Then …. Lambda calculus is more like writing mathematical formulas. There is no “doing”. When Turing learned of Church’s work, he wrote an appendix for his paper, showing that the two models were equivalent in power.
4
invented exactly sixty years ago by John McCarthy in 1958
Practical influences The Turing machine is arguably close in spirit to real computing devices. After all, it was conceived as machine. The Lambda calculus gave rise to a programming language, one of the earliest programming languages invented…. Lisp invented exactly sixty years ago by John McCarthy in 1958
5
In this class, we use Scheme
Lisp Many dialects evolved: MacLisp(1965), InterLisp (1970), ZetaLisp (1970), Lisp Machine Lisp (1975), Scheme (1975), …, Emacs Lisp (1985), …, Racket (1990), …. In this class, we use Scheme a subset of Racket that lines up with a subset of Scheme.
6
There is a tradition of using Scheme as an educational language.
When we designed CS17, we thought to contribute to that tradition.
7
Number of pages in description of language standard
Java standard reference has 436 pages. If you count the pages on the standard library, it’s 1363
8
“CS17 Scheme” Racket Scheme
9
Key ideas for today Data objects and types Textual representations and denotations of them Expressions and evaluations
10
Data 17 (1 3 5) atom + ( ) “hello, world” Intuitively, a datum is a mathematical object that the computer (or the language) can think about or remember. Datum or data object refers to the conceptual thing, independent of how it is represented in the computer or on the screen or on paper.
11
Types of data in our first language
Numbers Booleans Symbols Lists Functions (procedures) Real languages (including Scheme and Racket) allow you to create new data types—-but we won’t do that until Ocaml.
12
How they are represented in Scheme’s memory
Numbers Distinguish between How you can write them How Scheme writes them How they are represented in Scheme’s memory How you can write them: 17 The integer seventeen -17 The integer negative seventeen The real number that approximates pi 2/3 The fraction two-thirds 6.022e+23 Scientific notation 6.022✖️10²³ How does Scheme write them? It uses same formats—but not necessarily the same as you used. How are they represented? Won’t discuss now.
13
Boolean values represent the truth values of statements.
Booleans I have invented the rules of thought! Boolean values represent the truth values of statements. There are two Boolean values: true false George Boole, c. 1860 Other representations Scheme might use: #true, #false #t, #f
14
Symbol Sequence of letters and digits and punctuation marks Must not be interpretable as a number. Examples: cs17 MyName if.you#dare + * - / Mostly used as names to refer to other things. We will use in Eliza project: The words in a sentence are symbols. How do we represent the whole sentence?
15
LISP CYCLES (https://xkcd.com/297/)
Lists A list is a sequence of data objects. Any number (including zero). Scheme’s representation is very interesting. We’ll get to it later. Notation for lists? LISP CYCLES (
16
Lists Notation for lists?
A list is a sequence of data objects. Any number (including zero). Scheme’s representation is very interesting. We’ll get to it later. Notation for lists? Examples: ( ) (hello world) (+ 10 7) (+ (* 2 5) 7) (when the moon hits your eye ) Left parenthesis First item Space(s) Second item …. Last item Right parenthesis Item can be itself a list. (Extra spaces and even a newline doesn’t affect it.)
17
Sometimes helpful to visualize with a diagram.
Lists Because you can make a list whose items are lists, you can make an arbitrarily complicated data object. ((1 2) (a (b c d) e) (f)) Sometimes helpful to visualize with a diagram. Such a diagram is called a tree. In CS, trees are drawn upside down compared to biological trees.
18
Quiz Write a text that represents the list with first item the symbol a second item the list consisting of 1 and 2 third item the list with zero items (a (1 2) () )
19
Denotation versus expressions
Text: A sequence of characters that you or the computer writes. Denotation of a text: The data object that the text represents Examples: 17 denotes the integer seventeen Hello denotes a symbol + denotes a symbol (a b c) denotes a list (+ 10 7) denotes a list We will often elide the difference between text and its denotation, e.g. we will say “(a b c) is a list.” Some data objects can be evaluated. Evaluation is a complicated process but it follows certain rules, the Rules of Evaluation. Sometimes evaluation leads to a result, called the value. For example, the list denoted by (+ 10 7) evaluates to 17.
20
Rules of evaluation The value of a number is itself. The value of a Boolean is itself. The value of a symbol is the data object it is bound to. The value of a list is obtained as follows: First evaluate each item in the list. The first item should evaluate to a procedure. Apply the procedure to the values of the rest of the items. The result of the procedure application is the value of the list. Questions: What does bound to mean? What is a procedure? What does it mean to apply a procedure?
21
Examples (in arithmetic)
The symbol + is bound to the addition procedure. The symbol * is bound to the multiplication procedure. The symbol / is bound to the division procedure. The symbol - is bound to the subtraction procedure. (+ 7 10) evaluates to 17 (+ 7 (* 2 5)) evaluates to 17
22
Unwritten Quiz Evaluate (+ 2 (- 5 1))
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.