Book : Concept of Programming Language
Page 721
Review Question
2. A lambda expression specifies the parameters and the mapping of a function.
3. Atoms and lists were parts of the original LISP.
6. Simple list is a list which membership of a given atom in a given list that does not include sublists.
7. REPL stand for read-evaluate-print loop.
8. Three parameters to IF are: a predicate expression, a then expression, and an else expression.
18. A function is tail recursive if its recursive call is the last
operation in the function. This means that the return value of the
recursive call is the return value of the nonrecursive call to the
function. It is important to specify repetition to be tail recursive
because it is more efficient(increase the efficiency).
22. During reader phase of a common LISP language processor, There
is a special kind of macro, named reader macros or read macros, that are
expanded. A reader macro expands a specific character into a string of
LISP code. For example, the apostrophe in LISP is a read macro that
expands to a call to QUOTE.
24. What is stored in an ML evaluation environment?
A table called the evaluation environment stores the names of all
implicitly and explicitly declared identifiers in a program, along with
their types. This is like a run-time symbol table.
29. Curried function let new functions can be constructed from them by partial evaluation.
30. Partial evaluation means that the function is evaluated with
actual parameters for one or more of the leftmost formal parameters.
33. Explain the process of currying.
The process of currying replaces a function with more than one parameter
with a function with one parameter that returns a function that takes
the other parameters of the initial function.
35. A language is nonstrict if it does not have the strict requirement.
43. What is the syntax of a lambda expression in F#?
The following lambda expression illustrates their syntax:
(fun a b −> a / b)
Page 723
Problem Set
2. Give the general form of function declaration in ML.
Function declarations in ML appear in the general form
fun function_name( formal parameters ) = expression;
8. How is the functional operator pipeline ( | > )used in F#?
The pipeline operator is a binary operator that sends the value of
its left operand, which is an expression, to the last parameter of the
function call, which is the right operand. It is used to chain
together function calls while flowing the data being processed to each
call.
Consider the following example code, which uses the high-order functions filter and map:
let myNums = [1; 2; 3; 4; 5]
let evensTimesFive = myNums
|> List.filter (fun n −> n % 2 = 0)
10. What does the following Scheme function do?
(define ( x lis)
(cond
(( null? lis) 0 )
(( not(list? (car lis)))
(cond
((eq? (car lis) #f) (x (cdr lis)))
(else (+1 (x (cdr lis))))))
(else (+ (x (car lis)) (x (cdr lis))))
x returns the number of non-#f atoms in the given list
|> List.map (fun n −> 5 * n)
Tidak ada komentar:
Posting Komentar