2013-06-22

Programming Language Concept (6)

Book : Concept of Programming Language

Page 312
Review Questions
 1.  What is a descriptor?
A descriptor is the collection of the attributes of a variable.

2. What are the advantages and disadvantages of decimal data types?
The advantages of decimal data types is being able to precisely store decimal values, at least those within a restricted range, which can’t be done with floating-point. And the disadvantages of decimal data types are that the range of values is restricted because no exponents are allowed, and their representation in memory is mildly wasteful.

3. What are the design issues for character sting types?
The two most important design issues that are specific to character string types are the following:
- Should strings be simply a special kind of character array or a primitive type?
- Should strings have static or dynamic length?

4. Describe the three string length options.
- Static length string, the length can be static and set when the string is created.
- Limited dynamic length strings, allow strings to have varying length up to a declared and fixed maximum set by the variable’s definition.
- Dynamic length strings, allow strings to have varying length with no maximum.

8. What are the design issues for arrays?
The primary design issues specific to arrays are the following:
- What types are legal for subscripts?
- Are subscripting expressions in element references range checked?
- When are subscript ranges bound?
- When does array allocation take place?
- Are ragged or rectangular multidimensioned arrays allowed, or both?
- Can arrays be initialized when they have their storage allocated?
- What kinds of slices are allowed,if any?

11.How does JavaScript support sparse arrays?
JavaScript sparse arrays means that the subscript values need not be contiguous.

12. What languages support negative superscripts?
Ruby and Lua

13. What languages support array slices with stepsized?
Phyton, Perl, and Ruby.

14. What array initialization feature is available in Ada that is not available in other common imperative languages?
Ada provides two mechanisms for initializing arrays in the declaration statement: by listing them in the order in which they are to be stored, or by directly assigning them to an index position using the => operator, which in Ada is called an arrow.

23. What is the primary difference between a record and a tuple?
In tuple, the elements are not named.

24. Are the tuples of Phyton mutable?
No, Phyton includes an immutable tuple type.

32. What are the design issues for unions?
The primary design issues that are particular to union types are the following:
- Should type checking be required? Note that any such type checking must be dynamic.
- Should unions be embedded in records?

35. What are the design issues for pointer types?
The primary design issues particular to pointers are the following:
- What are the scope and lifetime of a pointer variable?
- What is the lifetime of a heap-dynamic variable?
- Are pointers restricted as to the type of value to which they can point?
- Are pointers used for dynamic storage management, indirect addressing, or both?
- Should the language support pointer types, reference types, or both?

43. What is a compatible type?
A compatible type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code to a legal type.

48. What languages have no type coercions?
Ada

Page 314
Problem Set

1. What are the arguments for and against four signed integer sized in Java?
Bytes =1 byte, short = 2 bytes, integer = 4 bytes, long  = 8 bytes. As a result, depending on the domain of the variable required, data types are used.

2. How are negative integers stored in memory?
A negative integer could be stored in sign-magnitude notation, in which the sign bit is set to indicate negative and the remainder of the bit string represents the absolute value of the number. Sign-magnitude notation does not lend itself to computer arithmetic. Most computers now use a notation called twos complement to store negative integers, which is convenient for addition and subtraction.

5. What disadvantages are there in implicit dereferencing of pointers, but only in certain contexts? For example, consider the implicit dereference of a pointer to a record in Ada when it is used to reference a record field.
When implicit dereferencing of pointers occurs only in certain contexts, it makes the language slightly less orthogonal. The context of the reference to the pointer determines its meaning. This detracts from the readability of the language and makes it slightly more difficult to learn.

7. Compare the pointer and reference type variable in C++.
A C++ reference type variable is a constant pointer that’s always implicitly dereferenced.

9. C provides two derived data types both for name and structure type equivalence: struct and union. Makes a study on when to use structtype variables and union type variables.
If all data members of the variables are to be used at once then struct type variables are required, otherwise union type variables should be used.

21. In what way is dynamic type checking better than static type checking?
Static checking reduces programmer flexibility.

22. Explain how the dangling-pointer problem can be removed using the locks-and-keys approach.
In the locks-and-keys approach, pointer values are represented as ordered pairs (key, address), where the key is an integer value. Heap-dynamic variables are represented as the storage for the variable plus a header cell that stores an integer lock value. When a heap-dynamic variable is allocated, a lock value is created and placed both in the lock cell of the heap-dynamic variable and in the key cell of the pointer that is specified in the call to new.

Tidak ada komentar:

Posting Komentar