2016-09-13 HW02

posted Sep 13, 2016, 6:11 AM by Samuel Konstantinovich   [ updated Sep 13, 2016, 2:28 PM ]
Homework HW02:
1. Log in to the homework server (also linked on the top level course page)
bert.stuy.edu/skonstantinovich/fall2016/pages.py
-pick your name from the drop-down,  your osis is your default password. (This is why you need to change it)
-Change your password and fill in your stuy.edu email, and your preferred name if you have one.
-Verify the changes, some of you will do this incorrectly, and if you don't check you won't know it didn't work.

2. 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.

Goal: Infix, prefix, and postfix

Infix notation:
<value1> <operator> <value2>
examples:  
2 + 3  
5 * 2

Prefix notation
<operator> <value1> <value2>
examples:  
+ 2 3     
* 5 2

Postfix notation
<value> <value> <operator>
examples:  
2 3 +      
5 2 *

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

Some operatiors suppor more than 2 values:
 (<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... because scheme has no order of operations, but infix does. You must pay attention to this.

If you want a mechanical way of doing this here:
(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 of the set of parenthesis that contains them.


Comments