Send a link to your students to track their progress
32 Terms
1
New cards
What is a Boolean value and what functions produce it?
A boolean value is a true or false statement that is created by functions <, >, <=, >= and =
2
New cards
What is a predicate?
A function which produces a Bool is a predicate. Many predicate names in Racket ends with ?.
3
New cards
What is a way we can write our own predicate?
(define (can-vote? age) (>= age 18)
4
New cards
What are string predicates?
Non-numeric types also have predicates. These predicates consume strings and are later used with on work with strings. (Ex: string=? "pearls" gems") -> false)
5
New cards
Describe conditional expressions.
Sometimes expressions should take one value under some conditions, and other values under other conditions.
6
New cards
What do conditional expressions do?
They are the key tool in Racket that allows us to vary the execution of the program depending on the condition that it encounters.
7
New cards
In what form are conditional expressions used in?
The special form cond.
8
New cards
Each arguments is a ____ pair.
question/answer
9
New cards
The ___ is a Boolean expression.
question
10
New cards
The ___ is a possible value of the conditional expression.
answer
11
New cards
How do we evaluate a cond?
We evaluate it by considering the question/answer pairs in order, top to bottom. When doing that, we evaluate the question. If the question evaluates to true, the whole cond produces the corresponding answer.
12
New cards
What happens if none of the questions evaluate to true?
An error occurs.
13
New cards
How do we fix the error?
We could use a question which always evaluates to true, which is used by else.
14
New cards
What is a trace?
The way we evaluate a program through a sequence of substitutions following rules we've defined.
15
New cards
What special forms do we use to combine predicates?
We use and, or, and the function not. These all consume and produce Bool values.
16
New cards
___ has value ___ when all of its arguments have value ___ and ___ otherwise.
and, true, true, false
17
New cards
___ produces ___ if at least one of its arguments is ___ and ___ otherwise.
or, true, true, false
18
New cards
___ produces ___ if its argument is ___, and ___ if its argument is ___
not, true, false, false
19
New cards
(and false ...) ->
false
20
New cards
(and true ...) ->
(and ...)
21
New cards
(and) ->
true
22
New cards
(or true ...) ->
true
23
New cards
(or false ...) ->
(or ...)
24
New cards
(or) ->
false
25
New cards
Tests, including examples, that have been defined before the body of the function was written are known as:
Closed-box texts because they are not based on details of the code.
26
New cards
Test that may depend on the code, for example, to check specific answers in conditional expressions are known as:
Open-box tests.
27
New cards
What is a symbol?
Racket allows one to define and use symbols with meaning to us. A symbol is defined using an apostrophe or 'quote': 'CS135
28
New cards
How can symbols be compared?
Using the predicate symbol=?
29
New cards
What is a character?
A character is most commonly a printed letter, digit, or punctuation symbol. a, G, ., + and 8 are all characters.
30
New cards
What are strings?
Strings are sequences of characters between double quotes. Examples: "pink" and "My hair is black"
31
New cards
What type of data are strings?
Strings are really compound data. (a string is a sequence of characters)
32
New cards
What is the contract for: 1. Numbers: 2. Integers: 3. Natural Numbers: 4. Booleans: 5. Characters: 6. Strings 7. Symbols 8. Values of any type
1. Num 2. Int 3. Nat 4. Bool 5. Char 6. Str 7. Sym 8: Any