Functions consume data and produce data. We say a function...
consumes its input, and
produces its output.
Data type, or just type defines
- A set of values
- A set of functions that consume those values
One data type in Scheme is number
All possible real numbers, like
−358277, − 1/3, 0, 1, 21, π, 256 ...
Functions that consume numbers include + − *, and /.
What we commonly call text - or a sequence of characters. Anything you can type on a keyboard.
A string is any sequence of characters enclosed in double quotes.
Some examples: "hello", "goodbye", "Nerds are cool.", "123456"
Important A sequence of digits enclosed in quotes is a string, not a number.
1234 is a number
"1234" is a string
A picture or image that can be displayed on the screen
Dr Racket can display many different images, including circles, squares, rectangles, and stars.
Documentation for Dr Racket Image Library
A contract shows what a function consumes and produces.
Here is the contract for +
;; + : number number -> number
A contract shows
- A function name
- Data types consumed
- Data types produced
The circle function consumes a number and two strings and produces an image.
;;circle : number string string -> image
The square function also consumes a number and two strings and produces an image.
;;square : number string string -> image
The ellipse function consumes two numbers and two strings and produces an image.
;;ellipse : number string string -> image
A function is nested
inside another function
Example from Unit 1
Example Using Ellipse
(ellipse 30 (+ 20 30) "solid" "red")