Functional Programming Languages
Assignment from Tri Djoko Wahjono
1. 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.
2. What does a lambda expression specify?
Lambda expressions describe nameless functions
3. What data types were parts of the original LISP?
Originally only atoms and lists
4. In what common data structure are LISP lists normally stored?
LISP lists are stored internally as single-linked lists
5. Explain why QUOTE is needed for a parameter that is a data list.
QUOTE is required because the Scheme interpreter, named EVAL, always evaluates parameters to function applications before applying the function. QUOTE is used to avoid parameter evaluation when it is not appropriate
6. What is a simple list?
A list that does not include a sublist.
7. What does the abbreviation REPL stand for?
Infinite Read-Evaluate-Print Loop
8. What are the three parameters to IF?
A predicate expression, a then expression, and else expression.
11. What are the two forms of DEFINE?
– To bind a symbol to an expression
– To bind names to lambda expressions
9. What does the following Scheme function do?
(define (y s lis)
((null? lis) ‘() )
((equal? s (car lis)) lis)
(else (y s (cdr lis)))
y returns the given list with leading elements removed up to but not including the first occurrence of the first given parameter.
10. What does the following Scheme function do?
(define (x lis)
((null? lis) 0)
((not (list? (car lis)))
((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-NIL atoms in the given list.