Concept of Programming Language Chapter 15

Assignment from Mr. Tri Djoko Wahjono

Review Questions
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 ?
– parameters and the mapping of a function.

3. What data types were parts of the original LISP ?
– atoms and lists

4. In what common data structure are LISP lists normally stored ?
– As linked list structure in which each node has two pointers.

5. Explain why QUOTE is needed for a parameter that is a data list.
– To return lists or atoms without changing them.

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 two forms of DEFINE ?
– Binds a name to value of an expression, and bind lambda expression to a name.

29. What is a curried function ?
– All functions that takes multiple parameters.

30. What does partial evaluation mean ?
– The function is evaluated with actual parameters for one or more of the leftmost formal parameters.

31. Define reader macros.
– A textual notation introduced by dispatch on one or two characters that defines special-purpose syntax

Problem Set
4. Refer to a book on Haskell programming and discuss the feature of Haskell.
– Haskell features lazy evaluation, pattern matching, list comprehension, type classes, and type polymorphism. It is a purely functional language, which means that in general, functions in Haskell do not have side effects. There is a distinct construct for representing side effects, orthogonal to the type of functions. A pure function may return a side effect which is subsequently executed, modeling the impure functions of other languages.
Haskell has a strong, static type system based on Hindley–Milner type inference. Haskell’s principal innovation in this area is to add type classes, which were originally conceived as a principled way to add overloading to the language, but have since found many more uses.
The construct which represents side effects is an example of a monad. Monads are a general framework which can model different kinds of computation, including error handling, nondeterminism, parsing, and software transactional memory. Monads are defined as ordinary datatypes, but Haskell provides some syntactic sugar for their use.

9. What does the following Scheme function do ?
(define (y s list)
((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 functions do ?
(define (x lis)
((null ? lis) 0)
((not (list? (car lis)))
((eq? (car lis) #) (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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s