Week 14 - FPL Flashcards
What is the design of imperative languages based on?
Von Neumann architecture.
Why is it challenging to manage the state changes in large imperative programs?
Managing the state changes in large imperative programs is a daunting task due to the importance of variables and how the program’s state changes.
What does a function definition specify?
A function definition specifies the domain and range sets along with the mapping described by an expression or table.
How are functions applied?
Functions are applied to elements of the domain set to yield elements of the range set.
What controls the evaluation order of mathematical functions?
The evaluation order is controlled by recursion and conditional expressions rather than sequencing and iterative repetition.
How are function definitions written?
Function definitions are written with the name, list of parameters in parentheses, and a mapping expression.
What is a higher-order function or functional form?
A higher-order function or functional form takes functions as parameters and yields a function as its result or does both.
Describe functional composition.
Functional composition is a functional form that takes two functions as parameters and yields a function whose value is the first actual parameter function applied to the application of the second, e.g., h(x) ≡ f(g(x)).
What is the apply-to-all functional form?
The apply-to-all functional form takes a single function as a parameter and yields a list of values obtained by applying the given function to each element of a list of parameters.
What is the objective of designing functional programming languages (FPLs)?
The objective of designing FPLs is to mimic mathematical functions.
How is the basic process of computation in FPLs different from imperative languages?
In FPLs, variables and assignments are not necessary, freeing the programmer from concerns of memory cells. Computation is performed through recursion rather than iterative constructs.
What is referential transparency in FPLs?
Referential transparency means the evaluation of a function always produces the same result given the same parameters, making the semantics of FPLs simpler than imperative languages.
What are primitive functions in FPLs?
Primitive functions are a set of basic functions provided in FPLs, with a smaller number being considered beneficial.
Why are output functions usually not needed?
Because the interpreter always displays the result of a function evaluated at the top level.
What is a predicate function?
A predicate function returns a Boolean value.
What does (= x 11) return if x is 11?
T.
What does (> x 11) return if x is 11?
().
What does (< x 15) return if x is 11?
T.
What does (EVEN? x) return if x is 11?
().
What does (ODD? x) return if x is 11?
T.
What is the COND function used for in Scheme?
Multiple selection.
What does the QUOTE function do in Scheme?
It takes one parameter and returns it without evaluation.
Why is the QUOTE function used in Scheme?
To avoid parameter evaluation when it is not appropriate.
How can QUOTE be abbreviated in Scheme?
With the apostrophe prefix operator.
What does (sort ‘(3 7 5 1 9)) return in Scheme?
(1 3 5 7 9).
What is tail recursion and why is it important in Scheme?
A function is tail recursive if its recursive call is the last operation in the function. Tail recursive functions can be converted to use iteration by the compiler, making them faster. Scheme requires that all tail recursive functions be converted to use iteration.
How is functional composition defined and used in Scheme?
Functional composition is when one function is applied to the result of another function. If h is the composition of f and g, then h(x) = f(g(x)).
How can Scheme functions build and evaluate code?
In Scheme, it is possible to define a function that builds Scheme code and requests its interpretation using the interpreter function EVAL.
How can a non-tail-recursive function be converted into a tail-recursive function in Scheme?
A non-tail-recursive function can be converted into a tail-recursive function by using an auxiliary helper function that carries an additional parameter to accumulate the result. This ensures that the recursive call is the last operation.
What is functional composition, and how is it implemented in Scheme?
Functional composition is the process of applying one function to the result of another. In Scheme, it can be implemented using the compose function, which takes two functions f and g and returns a new function that applies f to the result of g.
What do functional programming languages (FPLs) mimic and why is this important?
FPLs mimic mathematical functions, which is important because it allows for a more predictable and reliable way to manage data and behavior, as functions always produce the same output given the same input without side effects.
n functional programming, what replaces loops and why?
Recursion replaces loops in functional programming because it allows iteration without changing state, maintaining immutability and functional purity.