Index: [thread] [date] [subject] [author]
  From: Robert C. Duvall <rcd@cs.duke.edu>
  To  : 
  Date: 02 Feb 1999 00:13:30 -0500

Arithmetica notes

Think about the following example (from the assignment sheet) and be
prepared to explain how your program works with respect to it:

       Welcome to Arithmetica
       > 3 + 7 * 2
       17

new expression: resets !! to 3 + 7 * 2 
                and prints result

       > (3 + 7) * 2
       20

new expression: resets !! to (3 + 7) * 2 
                and prints result

       > + 10
       30

combine expression: updates !! to ((3 + 7) * 2) + 10 
                    and prints result

       > * 10
       300
combine expression: updates !! to (((3 + 7) * 2) + 10) * 10
                    and prints result

       > --!!
       299

combine expression: updates !! to (((3 + 7) * 2) + 10 * 10) - 1 
                    and prints result

       > a = 2 ^ 4
       16

assignment: assigns 2 ^ 4 to variable a
            and, I assume, does not update !!

       > b = 16
       16

assignment: assigns 16 to variable b
            and, I assume, does not update !!

       > c = a - b
       0

assignment: assigns a - b (i.e., (2 ^ 4) - 16) to variable c
            and, I assume, does not update !!

       > b = 2 * 16
       32

assignment: assigns 2 * 16 to variable b
            and, I assume, does not update !!

       > c
       -16

variable access: prints value of c (i.e., (2 ^ 4) - (2 * 16))
                 and, I assume, does not update !!
  
       > a = ++b
       33

assignment: assigns b + 1 (i.e., (2 * 16) + 1) to variable a
            and, I assume, does not update !!

       > c
       1

variable access: prints value of c (i.e., ((2 * 16) + 1) - (2 * 16))
                 and, I assume, does not update !!
  
       > print(c)
       ((a) - (b))

function call: evaluates function print
               and does not update !!

               I think I consider this a typo, it should print
       (((2 * 16) + 1) - (2 * 16))
               (i.e., recursively expand the variables).  This change
	       means you do not need to special case printing variables


       > sum(a, b, c, !!, (3 + 7) * 2)
       351

function call: evaluates function sum of:
	       ((2 * 16) + 1) + 
	       (2 * 16) +
               (((2 * 16) + 1) - (2 * 16)) +
               ((((3 + 7) * 2) + 10 * 10) - 1) +
	       ((3 + 7) * 2)
               and does not update !!

       > ^D


In short, I assumed that only new expressions and combinations updated
the current expression (!!).  It is okay if your program updates the
current expression _every_ time the user types return, that just means
you will get different output from my example.  Again, you should
DOCUMENT the behavior of your program.

rcd


-- 
Robert C. Duvall
Lecturer, Duke University
rcd@cs.duke.edu


Index: [thread] [date] [subject] [author]