Harmony Clean Flat Responsive WordPress Blog Theme

Assignment 8

Review Questions:
  1. What is unusual about Python’s design of compound statements?
  • Python uses indentation to specify compound statements. For example,
    if x > y :
    x = y
    print “condition 1″
    equally indent statements are grouped as one compound statement.
  1. Under what circumstances must an F# selector have an else clause?
  • An F# selector have an “else” clause if the “if” expression does return a value.
  1. What are the common solutions to the nesting problem for two-way selectors?
  • First one is to use A static semantics rule, rather than a syntactic entity, which used to provide the disambiguation. Another way to avoid the issue of nested selection statements is to use an alternative means of forming compound statements.
  1. What are the design issues for multiple-selection statements?
  • What is the form and type of the expression that controls the selection?
  • How are the selectable segments specified?
  • Is execution flow through the structure restricted to include just a single selectable segment?
  • How are the case values specified?
  • How should unrepresented select or expression values be handled, if at all?
  1. Between what two language characteristics is a trade-off made when deciding whether more than one selectable segment is executed in one execution of a multiple selection statement?
  • for multiple selectors is a trade-off between reliability and flexibility.
Problem Sets:
  1. Analyze the potential readability problems with using closure reserved words for control statements that are the reverse of the correspond
ing initial reserved words, such as the case-esac reserved words of ALGOL 68. For example, consider common typing errors such as transposing characters.
  • The potential readability problems with using closure reserved words for control statements that are the reverse of the correspond
ing initial reserved words is that we might get typing error, which make it less readability.
  1. Use the Science Citation Index to find an article that refers to Knuth (1974). Read the article and Knuth’s paper and write a paper that summarizes both sides of the goto issue.
  • An alternative viewpoint is presented in Donald Knuth’s Structured Programming with go to Statements, which analyzes many common programming tasks and finds that in some of them GOTO is the optimal language construct to use.In their quasi-standard book on the C programming language, Dennis Ritchie and Brian Kernighan warn that goto is “infinitely abusable”, but also suggest that it could be used for end-of-function error handlers and for multi-level breaks from loops.
  1. In his paper on the goto issue, Knuth (1974) suggests a loop control statement that allows multiple exits. Read the paper and write an operational semantics description of the statement.
  • When using a count-controlled loop to search through a table, it might be desirable to stop searching as soon as the required item is found. Some programming languages provide a statement such as break (most languages), exit, or last (Perl), whose effect is to terminate the current loop immediately and transfer control to the statement immediately following that loop.
For example:
for n in set_of_numbers:
if isprime(n):
print “Set contains a prime number”
break
else:
print “Set did not contain any prime numbers”
  1. What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also allowing arithmetic expressions, as in C++)?
  • The for statement of C99 and C++ differs from that of earlier versions of C in two ways. First, in addition to an arithmetic expression, it can use a Boolean expression for loop control. Second, the first expression can include variable definitions. For example,
for (int count = 0; count < len; count++) {…}
The scope of a variable defined in the for statement is from its definition to the end of the loop body.The for statement of Java and C# is like that of C++, except that the loop control expression is restricted to boolean.
  1. In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++, unrepresented values can be caught at run time with the default selec- tor. If there is no default, an unrepresented value causes the whole statement to be skipped. What are the pros and cons of these two designs (Ada and C++)?
  • For c++ :
  1. Control expression can be only an integer type
  2. Selectable segments can be statement sequences, blocks, or compound statements
  3. Construct is encapsulated
  4. Any number of segments can be executed in one execution of the construct (there is no implicit branch at the end of selectable segments) (a trade-off between reliability and flexibility–convenience)
– To avoid it, the programmer must supply a break statement for each segment.
  1. default clause is for unrepresented values (if there is no default, the whole statement does nothing)
  • While for Ada:
  1. Constant lists can include:
– Subranges e.g., 10..15
– Boolean OR operators
e.g., 1..5 | 7 | 15..20
  1. Lists of constants must be exhaustive
– Often accomplished with others clause
– This makes it more reliable