Concept of Programming Language Chapter: 15

Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc

BY : NETTY SETIAWAN

from: 02PCT

NIM: 1601221572

REVIEW QUESTIONS

2.   What does a lambda expression specify?

A lambda expression specifies the parameters and the mapping of a function.

3.   What data types were parts of the original LISP?

Atoms and lists.

6.   What is a simple list?
A list which membership of a given atom in a given list that does not include sublists.

7.   What does the abbreviation REPL stand for?
REPL stand for read-evaluate-print loop.

8.   What are the three parameters to IF?

Three parameters to IF are: a predicate expression, a then expression, and an else expression.

18.   What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive?
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.  What happens during reader phase of a common LISP language processor?

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. What is a curried function?
Curried function let new functions can be constructed from them by partial evaluation.

30.  What does partial evaluation mean?

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.   When is a programming language called a nonstrict language?

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)

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)

Leave a comment