Friday, June 28, 2013

Concepts of Programming Languages Chapter 15


Concepts of Programming Languages Chapter 15


Name            : Erland
NIM              : 1601218035
Lecturer       : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment  : Concept of programming languages Chapter 15

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

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

           29. What is a curried function?

Curried functions are interesting and useful because 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.

          31. Define reader macros.

Reader macros or read macros, that are expanded during the reader phase of a LISP languageprocessor. 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. Users can define their own reader macros to create other shorthand constructs.

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

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.



         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)
|> List.map (fun n −> 5 * n)



          9. What does the following Scheme function do?
(define (y s lis)(cond((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.