Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Imperative Functional
1. The same name may be associated 1. A name is only ever associated with
with different values. one value.
2. Efficient execution 2. Inefficient execution
3. Complex semantics 3. Simple semantics
4. Complex syntax 4. Simple syntax
5. Concurrency is programmer 5. Programs can automatically be made
designed concurrent
6. Order of execution is Important 6. Order of execution is low important
PART-B
5. (a) Define subprograms. What are the advantages of subprograms? Explain
different methods of parameter passing mechanisms to subprograms
Ans. A subprogram definition describes the interface to and the actions of the
subprogram abstraction
Advantages:
They help keep the code simple, more readable;
They allow the programmer to define needed functions;
They can be used in other programs.
provide modularity and promote reusability and maintainability.
Parameter Passing Methods
--Semantics models of parameter-passing methods.
--implementation models for these semantics models
1
Semantic Models
Formal parameters are characterized by one of three distinct semantics models:
(1) They can receive data from the corresponding actual parameter -- in mode
(2) they can transmit data to the actual parameter -- out mode or
(3) they can do both -- inout mode.
Implementation Models of Parameter Passing
A variety of models have been developed by language designers to guide the
implementation of the three basic parameter transmission modes.
1. Pass-by-value
2. Pass-by-result
3. Pass-by-value-result
4. Pass-by-reference
5. Pass-by-name
1. Pass-by-value (In Mode)
•The value of the actual parameter is used to initialize the corresponding formal
parameter
2. Pass-by-Result (Out Mode)
When a parameter is passed by result, no value is transmitted to the
3. Pass-by-Value-Result (inout Mode)
•A combination of pass-by-value and pass-by-result
• •Formal parameters have local storage
4. Pass-by-Reference (Inout Mode)
Also called pass-by-sharing
•Pass an access path
5. Pass-by-Name (Inout Mode)
•By textual substitution
•Formals are bound to an access method at the time of the call, but actual binding to
a value or address takes place at the time of a reference or assignment
exception_choice form:
exception_name | others
Handlers are placed at the end of the block or unit in which they occur
Binding Exceptions to Handlers
If the block or unit in which an exception is raised does not have a handler for that
exception, the exception is propagated elsewhere to be handled
o Procedures - propagate it to the caller
o Blocks - propagate it to the scope in which it appears
2
o Package body - propagate it to the declaration part of the unit that declared the
package (if it is a library unit, the program is terminated)
o Task - no propagation; if it has a handler, execute it; in either case, mark it
"completed"
Other Design Choices
User-defined Exceptions form:
o exception_name_list : exception;
Raising Exceptions form:
o raise [exception_name]
o (the exception name is not required if it is in a handler--in this case, it
propagates the same exception)
Exception conditions can be disabled with:
o pragma SUPPRESS(exception_list)
Predefined Exceptions
Constraint_Error - index constraints, range constraints, etc.
Program_Error - call to a subprogram whose body has not been elaborated
Storage_Error - system runs out of heap
Tasking_Error - an error associated with tasks
Evaluation
Ada was the only widely used language with exception handling until it was added to
C++
The propagation model allows exceptions to be propagated to an outer scope in which
the exception would not be visible
It is not always possible to determine the origin of propagated exceptions
Exception handling is inadequate for tasks
6. a) Explain about LISP and HASKELL Functional programming languages
LISP Interpretation
Haskell
3
•Similar to ML (syntax, static scoped, strongly typed, type inferencing, pattern
matching)
•Different from ML (and most other functional languages) in that it is purely functional
(e.g., no variables, no assignment statements, and no side effects of any kind)
fact n
| n == 0 = 1
| n > 0 = n * fact(n – 1) sub n
| n < 10 = 0
| n > 100 = 2 | otherwise = 1
square x = x * x - Works for any numeric type of x
4
o –Describe how new propositions can be inferred from other propositions. (Particular
form of symbolic logic used for logic programming called predicate Calculus)
Object Representation
•Objects in propositions are represented by simple terms: either constants or variables
•Constant: a symbol that represents an object
•Variable: a symbol that can represent different objects at different times