Assignment 6, Order of evaluation and subtyping
Due 10/14/03 12 noon
(To be done with your group)

NOTE: Several of you indicated on the surveys that you would like more attempts for the PL-Detective.   Starting with the previous assignment assignment, I've been giving you more attempts than before for the PL-Detective.  Rather than using a straightforward formula (e.g., 2*minimum number of attempts), I'm selecting the number of attempts based on the difficulty of the question.

  1. From the mystery grammar we see that all operators (+, >, AND) are left associative and have the same precedence.  Real languages, such as Java and C++ often put these operators at a different precedence.
    1. For one of C, C++, or Java figure out the precedence and associativity of the three operators in MYSTERY.  You may accomplish this by writing programs in the language or by looking up a book or language definition for the language.  In your answer give either the programs that you used or quotes from the book/language definition that support your answer.
    2. What are the implications of having the three operators at the same level in MYSTERY?  In other words, give an expression in your chosen language (i.e., C, C++, or Java) that would evaluate differently (or not evaluate at all) in MYSTERY.  Explain your answer.
    3. Problem set p. 315, #4
  2. Calls are amongst the most complicated expression construct in programming languages.  There are many, many different ways of supporting calls and different languages often differ in their support for calls.  In this question, we will consider only the evaluation order issues with calls; later in the semester we will consider other issues.

    Let's consider the following abstract call F(A1, ... An)F is the procedure being called.  While we are used to calling a procedures directly (e.g., print(...)), most languages, including MYSTERY allow complicated expressions for F.  For example, if a is an array of procedures, one can do a[2](5) in MYSTERY to call the procedure at a[2] with argument 5MYSTERY even allows a procedure to return a procedure.  Thus, if a procedure, f, returns a procedure, then one could write f()(x).  This calls the procedure returned by f with the argument x.  Needless to say, most languages allow one to pass arbitrarily complicated arguments (i.e., Ai). 

    1. Come up with and describe a compelling example of why would one want to return a procedure from a procedure.
    2. Discover whether MYSTERY evaluates the procedure being called before it evaluates its arguments.  For example, with f()(x) does MYSTERY call the function f first or does it evaluate x first (i.e., looks up the value of x).  You may execute up to 4 PRINT statements.   
    3. Discover whether or not MYSTERY evaluates arguments to a call from left-to-right.  You may execute up to 4 PRINT statements.

    Use this link to submit programs.  You should provide evidence that supports your argument.  You will lose 5% of the points for this question for each additional executed PRINT. 

  3. Give and explain an example that shows that ARRAY I OF T <: ARRAY I OF U, if T <: U is an incorrect subtyping rule for updatable arrays.
  4. Should a boolean type be a subtype of an integer type?  Defend your case.