Review Questions (Ch15): Functional Programming Languages

Ace your homework & exams now with Quizwiz!

# 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).

# What is a simple list?

A list that does not include a sublist.

# What are the three parameters to IF?

A predicate expression, a then expression, and else expression.

# What is the use of evaluation environment table?

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. When an identifier is declared, either implicitly or explicitly, it is placed in the evaluation environment.

# Define reader macros.

A textual notation introduced by dispatch on one or two characters that defines special-purpose syntax

# What is a curried function?

All functions that takes multiple parameters.

# In what common data structure are LISP lists normally stored?

As linked list structure in which each node has two pointers.

# What data types were parts of the original LISP?

Atoms and lists

# What are two forms of DEFINE?

Binds a name to value of an expression, and bind lambda expression to a name.

# Define functional form, simple list, bound variable and referential transparency.

Functional form : one that either takes one or more functions as parameters or yields a function as its result. Simple list : A list that does not include sublist. Bound variable : A bound variable is a variable which never changes in the expression after being bound to an actual parameter value at the time evaluation of the lambda expressions begin. Referential transparency : A state where execution of function always produces the same result when given the same parameters.

# What does the abbreviation REPL stand for?

Infinite Read-Evaluate-Print Loop

# Why were imperative features added to most dialects of LISP?

LISP began as a pure functional language but soon acquired some important imperative features to increased its execution efficiency.

# What does partial evaluation mean?

The function is evaluated with actual parameters for one or more of the leftmost formal parameters.

# What is type inferencing, as used in ML?

Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction.

# What does a lambda expression specify?

Parameters and the mapping of a function.

# Why are CAR and CDR so named?

The names of the CAR and CDR functions are peculiar at best. The origin of these names lies in the first implementation of LISP, which was on an IBM 704 computer. The 704's memory words had two fields, named decrement and address, that were used in various operand addressing strategies. Each of these fields could store a machine memory address. The 704 also included two machine instructions, also named CAR (contents of the address part of a register) and CDR (contents of the decrement part of a register), that extracted the associated fields. It was natural to use the two fields to store the two pointers of a list node so that a memory word could neatly store a node. Using these conventions, the CAR and CDR instructions of the 704 provided efficient list selectors. The names carried over into the primitives of all dialects of LISP.

# What is the use of the fn reserved word in ML?

The predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless.

# 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.

# What is the syntax of lambda expression in F#?

The syntax in F# is (fun a b −> a / b)

# Describe the syntax and semantics of COND.

The syntax of COND is (COND (predicate1 expression1) (predicate2 expression2) . . . (predicaten expressionn) [(ELSE expressionn+1)] ) The semantics of COND is as follows: The predicates of the parameters are evaluated one at a time, in order from the first, until one evaluates to #T. The expression that follows the first predicate that is found to be #T is then evaluated and its value is returned as the value of COND. If none of the predicates is true and there is an ELSE, its expression is evaluated and the value is returned. If none of the predicates is true and there is no ELSE, the value of COND is unspecified. Therefore, all CONDs should include an ELSE.

# Explain why QUOTE is needed for a parameter that is a data list.

To return lists or atoms without changing them.


Related study sets

Organizational Communication Exam 3 UNCC (Dr. Gossett Spring 2018)

View Set

Distributed Computing System MCQs

View Set

PA Property & Casualty Insurance Exam (C)

View Set

8 Antibacterial Drugs That Interfere With Protein Synthesis

View Set

Solutions Exam: Multiple Choice and Math

View Set

Genetica - Capitolo 1: struttura e funzione del DNA

View Set

Chapter 5: Consumer Credit: Advantages, Disadvantages, Sources, and Costs

View Set