You are on page 1of 3

Chapter 14

1. Define functional form and referential transparency.

Functional form - one that either takes functions as parameters or yields a function at its result, or both.
Referential transparency - The execution of a function always produces the same result when given the same
parameters.

2. What data types were part of the original LISP?

Atoms and lists

3. What is the difference between EQ?, EQV?, and =?

EQV? works on both numeric and symbolic atoms


EQ? works for symbolic atoms but not necessarily for numeric atoms
= works for numeric atoms, but not symbolic atoms

4. What are the differences between the evaluation method used for the Scheme special form, DEFINE, and that
used for its primitive functions?

DEFINE is a special form because it is interpreted in a different way than the normal primitives like CAR and the
arithmetic functions. The simplest for of DEFINE is one used to bind a symbol to the value of an expression.

5. What are the two forms of DEFINE?

The simplest for of DEFINE is used to bind a symbol to the value of an expression. Example: (DEFINE pi 3.14159)
The DEFINE function can also be used to bind a lambda expression to a name. In this form, DEFINE takes two
lists as parameters. The first parameter is the prototype of a function call, with the function name followed by the
formal parameters, all in a list. The second list is the expression to which the name is to be bound. Example:

(DEFINE (function_name parameters)


body
)

6. Describe the semantics of COND.

COND is a slightly generalized version of the mathematical conditional expression; it allows more than one
predicate to be true at the same time.

(COND
(predicate_1 expression { expression})
(predicate_2 expression { expression})
...
(predicate_n expression { expression})
(ELSE expression {expression})
)

7. Describe the semantics of LET.

The semantics of LET is that the first n expression s are evaluated and the resulting values are bound to their
associated names. Then the epressions in the body are evaluated. The result of LET is the value of the last
expression in its body.

(LET
(name_1 expression_1)
(name_2 expression_2)
...
(name_n expression_n)
body
)
8. Why were imperative features added to most dialects of LISP?

9. In what ways are COMMON LISP and Scheme opposites?

Scheme is far smaller and somewhat cleaner, in part because of its exclusive use of static scoping. COMMON LISP
was meant to be a commercial language and has succeeded in being a widely used language for AI applications.
Scheme, on the other hand, is more frequently used in college courseso n functional programming. It is also more
likely to be studied as a functional language because of its relativelysmall size. An important design criterion of
COMMON LISP that caused it to be a very large language is the desire to make it compatible with several earlier
dialects of LISP.

10. What scoping rule is used in Scheme? In COMMON LISP? In ML? In Haskell?

11. What are three ways that ML is very different from Scheme?

1. It uses a syntax that is more similar to that of Pascal than that of LISP
2. It has type declarations, uses type inferencing, which means that variables need not be declared, and it is strongly
typed.
3. The type of every variable and expression can be determined at compile time.

12. What is type inferencing, as used in ML?

Type inferencing, means that variables need not be declared, and it is strongly typed. The type of every variable
and expression can be determined at compile time.

13. What are three features of Haskell that make it very different from Scheme?

14. What does lazy evaluation mean?

Lazy Evaluation - no subexpression is evaluated until its value is known to be required.

Chapter 14 - Handout

Question 1

Strike out 2nd item of a simple list with 2 or more elements else NIL if there are less than two elements.

( define (strike2 1)
(cond
((>= (length 1) 2)
(cons (car 1) ( cddr 1 ))
)
( T NIL)
)
)

if defined using an if...

(define (strike2 1)
(if (>= (length 1) 2)
(cons (car 1) (cddr 1) )
NIL
)
)

Question 2

Complete the definition of the union of two simple lists L1 and L2 (define (union L1 L2) ???)

(define (union a b )
(cond
( ( null a) b)
(( null b) a)
((member (car a) b) (union (cdr a) b))
(T (cons (car a) (union (cdr a) b )))
)
)

[ Up ]

You might also like