09-16-2013 HW e

posted Sep 16, 2013, 5:40 AM by Samuel Konstantinovich   [ updated Oct 3, 2013, 5:14 AM ]
Infix, prefix, and postfix

Infix notation:
value1 operator value2
example:  2 + 3  5 * 2

Prefix notation
operator value1 value2
example:  + 2 3     * 5 2

Postfix notation
value value operator
example:  2 3 +      5 2 *

Scheme notation
Prefix with required the parenthesis: before the operator and after the final operand:
(operator  value1 value2 ... valueN)

Converting 
converting from infix to prefix requires you to know the order of operations. 
2+ 3 * 4    ->  (+ 2 (* 3 4))
2 * 3 + 4  ->  (+ (*2 3) 4)

Think about where the parenthesis could go for infix to help you convert:
2 * 3 + 4   is really (2 * 3) + 4  which coverts more easily.

Be careful when converting 
(4+5) / 6 * 2        Start with this tricky example
(((4 + 5) / 6) * 2)  Add more parenthesis to remind yourself of the order of operations
(* (/ (+4 5) 6) 2)   Now move the operators to the beginning

Homework:
Test DrRacket at home. 
Test functions by evaluating them and then tracing through it.
Make sure the way you evaluate an expression is the same way that DrRacket traces through it. This is open ended... the people that aren't 100% confident should make a few extra attempts at correcting their way of thinking. If you are confident, you should verify that you are correct.
Comments