Lecture 1
Programming in Text
Big ideas from Data Flow
Review 0. (not a question)
Review 1.
exceptions
What’s the output of this diagram?
Exceptions
Wrong number of inputs
What about this one?
What about this one?
concat needs two strings!
What about this one?
What about this one?
Argument type exception
Type signatures
Types and type checking
Argument type
exception
Type signatures
Types and type checking
Functions / Programs as data
“type error in
call to prefix”
check
Programming in Text
The�language question
What’s the best language?
The “Racket” language
We'll start the quarter using Racket’s Intermediate Student Language
This is ISL+ (intermediate student language)
COMP_SCI 111 Lore
Basics of ISL+
Functionality
Functional Aesthetics
Turning DFD into Text Programs
Let's figure out how to turn this into a text program
Names
Name Type 1: Constants
Examples (we'll see more types later)
Name Type 2: Variables
So that means…
So that means…
constant (number)
constant (number)
variable
(name: +)
(value: the plus function)
How do we call or execute a function?
constant (number)
constant (number)
variable
(name: +)
(value: the plus function)
The call function
Function calls
function input1 … inputn
(function input1 … inputn)
Examples:
Note: + and string-append can allow variable numbers of inputs in Racket (i.e. they are variadic)
Equivalent diagrams
(+ 1 2) means:
or really:
Skills to build
Look at a data flow diagram and:
extra
exercises
Which of these has problems?
Which of these has problems?
+
1
2
+
4
1
+
2
+
2
4
call
1
+
1
call
1
2
3
+
Bad function
(1 isn’t a function)
Which of these has problems?
Which of these has problems?
call
1
2
+
call
call
+
2
1
call
1
2
+
call
4
+
“woof woof”
prefix
+
5
length
Bad function
(3 isn’t a function)
3
9
14
Index out of range
(string doesn’t have 14 characters)
Bad function
(1 isn’t a function)
Chained (nested) calls
(function input1 … inputn)
Examples
"this "� (string-append "is a "
"test"))
"blue")
(square 10� "solid"
"red"))
There’s always exactly one call for every pair of parens
Parentheses always mean call (for now)
There’s always exactly one call for every pair of parens
Parentheses always mean call (for now)
(+ 1 2)
((+ 1 2))
(+ (1) 2)
There’s always exactly one call for every pair of parens
Parentheses always mean call (for now)
(+ 1 2)
((+ 1 2))
(+ (1) 2)
Function position vs argument position
What are the text versions of these DFDs?
What are the text versions of these DFDs?
(string-append
(string-append "this "
"is a ")
"string")
(+ (+ 1 2) 4)
What’s the text for this DFD?
What’s the text for this DFD?
(string-append (string-append (string-append "this " "is a ") "tedious ") (string-append "example of " "chaining"))
Subexpressions and data flow
Subexpressions and data flow
(string-append (string-append (string-append "this " "is a ") "tedious ") (string-append "example of " "chaining"))
Running code�in DrRacket
Using DrRacket
Our Style Rules for this Class
What to do when it breaks
Making it legible
(string-append (string-append (string-append "this " "is a " "tedious ") (string-append "example of " "chaining")))
Making it legible
(string-append (string-append (string-append "this " "is a " "tedious ") (string-append "example of " "chaining")))
Making it legible
(string-append (string-append (string-append "this "
"is a "
"tedious ")
(string-append "example of "
"chaining")))
Making it legible
(string-append (string-append (string-append "this "
"is a ")
"tedious ")
(string-append "example of "
"chaining"))
(string-append (string-append (string-append "this "
"is a ")
"tedious ")
(string-append "example of "
"chaining"))
Indented code is a DFD (just written right to left)
Making it mutually intelligible
Keeping your code indented