Send a link to your students to track their progress
42 Terms
1
New cards
Imperative Language and Examples?
Based on frequent changes to data. (Ex: Machine language, Java, C++, Turing, Visual Basic, Python)
2
New cards
Functional Language and Examples?
Based on the computation of new values rather than the transformation of old ones. (Ex: Racket, Excel formulas, LISP, ML, Haskell)
3
New cards
What are a subset of Racket?
Graduate set of teaching languages
4
New cards
What is the background of racket?
A dialect of Scheme and a descendant of Lisp
5
New cards
What are the two windows of Racket?
Interactions (now) and Definitions (later)
6
New cards
What is the Interactions window of Racket?
A read-evaluate-print loop (REPL)
7
New cards
Are integers in Racket bounded or unbounded?
Unbounded
8
New cards
How are rational numbers represented?
Exact
9
New cards
Expressions whose values are not rational numbers are flagged as being:
Inexact (Ex: [sqrt 2] -> #i1.4142135623709)
10
New cards
Given: f(x) = x^2, g(x, y) = x + y 1. What is the name of the function? 2. What is its parameters?
1. g 2. (x, y)
11
New cards
An ____ of a function supplies ___ for the ____, which are substituted into the algebraic expression.
1. application 2. arguments 3. parameters
12
New cards
Define Canonical form
A natural unique representation of an object, or a preferred notation for some object
13
New cards
What are the two rules for canonical substitutions?
1. Functions are applied to values 2. When there is a choice of possible substitutions, always take the leftmost choice
14
New cards
What are the two uses of parentheses?
1. Function application 2. To specify ordering
15
New cards
+, - are examples of:
Infix/Arithmetic operators
16
New cards
When should parentheses be used in Racket?
To signal a function application or some other Racket syntax
17
New cards
A syntax error is:
An error discovered when reading an expression. Ex: (* (5) 3)
18
New cards
A run-time error is:
An error discovered when evaluating an expression. Ex: (/ 25 0)
19
New cards
e and pi are examples of:
Constant
20
New cards
(abs x), (max x y ..), (ceiling x) are examples of:
Functions
21
New cards
A function definition consists of:
1. A name for the function 2. A list of parameters 3. A single body expression
22
New cards
Give (define (g x y) (+ x y): 1. What does define do? 2. What is the name of the function? 3. What are the parameters? 4. What is the body (expression)?
1. "binds" name to body 2. g 3. (x y) 4. (+ x y)
23
New cards
What is define and what does it do?
define is a special form that binds a name to an expression (which uses the parameters that follow the name).
24
New cards
What does an application of a user-defined function do?
It substitutes arguments for the corresponding parameters throughout the definition's expression.
25
New cards
What are identifiers?
Functions and parameters are named by identifiers, like, f, x-ray, WhaTeVer.
26
New cards
What can identifiers not contain?
Space, brackets of any kind, or quotation marks
27
New cards
Does changing names of parameters change what the function does?
No
28
New cards
Can functions use the same parameter name?
Yes
29
New cards
Does parameter order matter?
Yes
30
New cards
What does (define k 3) do?
Binds the name k to the value 3.
31
New cards
What does (define p (sqr k)) do?
The expression (sqr k) is first evaluated to give 9, and then p is bound to that value.
32
New cards
What are the advantages of Constants?
1. can give meaningful names to useful values 2. reduce typing and errors when such values need to be changed 3. make programs easier to understand
33
New cards
pi and e are:
built-in constants
34
New cards
Where can constants be used?
In any expression, including the body of function definitions
35
New cards
What is a helper function?
A function that helps implement another function.
36
New cards
What 3 purposes are helper functions used for?
1. Reduce repeated code by generalizing similar expressions 2. Factor out complex calculations 3. Give meaningful names to operations
37
New cards
1. Where are helper functions placed? 2. What are the exceptions?
1. After the function that uses them. 2. i) Helpers used to define constants must be defined before being used. For (define c (distance 1 1 3 9)), distance must be already defined ii) Helpers used in several functions in the same file are often placed first iii) The order of functions specified in an assignment takes precedence over the rules above
38
New cards
What is a scope and what are the two kinds of scope?
The scope of an identifier is where it has effect within the program. The two kinds are global and function. The smallest enclosing scope has priority where duplicate identifiers within the same scope will cause an error.
39
New cards
What is a Racket program?
A Racket program is a sequence of definitions and expressions.
40
New cards
What do the expressions do?
The expressions are evaluated, using substitution, to produce values.
41
New cards
Expressions make use of what?
Expressions may also make use of special forms (e.g. define), which look like functions, but don't necessarily evaluate all their arguments.