EXPRESSION FORMATS

TOPIC 01 – PREFIX NOTATION

 

LESSON WORK

 

 

TASK 1


Evaluate the following prefix expressions:

 

a)                      / 9 3

b)                      + 5 – 3 2

c)                      * 7+ 4 2

d)                      / 100 + 5 + 3 2

e)                      – + 10 2 * 4 1

 

TASK 2 – EXPLORING IN RACKET

 

Racket is a functional programming language.  It allows you to work with prefix notation.  You can do so using an online IDE or you can go ahead and install Racket on your computer if you prefer.

 

 

OPTION 1 – ONLINE RACKET IDE (EASIER & PROBABLY BETTER OPTION)

 

Use Google and search for Racket Online.  You will find several sites that offer Racket IDE access online.

 

Here is one link that works: https://www.jdoodle.com/execute-racket-online/

 

To test prefix notation on this site, you will need to use:

 

(writeln(+ 4 5))

 

and then hit Execute.

 

 

OPTION 2 – FULL INSTALLATION (USEFUL IF YOU WANT TO SPEND TIME IN RACKET)

 

If you have an interest in learning Racket, you can install it on your computer.  Racket is a functional programming language (https://racket-lang.org/).  It comes with a programming software (IDE) called Dr. Racket which is what you will open to do work.

The window is separated into two parts.  The top part allows you to create a program that you can run all at once.  The bottom part allows you to type in individual commands one at a time.

 

You can tell Racket to evaluate an arithmetic expression simply by typing out the expression at the bottom.  Of course, it has to be in prefix notation.  And, Racket requires that you put brackets around each operation.  See below for an example.

 

 

 

TASK 3

Write the following infix expressions in prefix racket notation and try them in Racket.  Note that prefix racket notation is simply prefix notation with brackets around every operation.

 

                   So instead of

                        + 5 – 7 2

 

                   You would write

 

                        (+ 5 ( - 7 2 ))

 

Make sure you write your final answers down somewhere so you don't forget them.

 

a)                      7 * 2 – 4
The answer should be 10.

b)                      14 – 2 * 7
The answer should be 0.

c)                      8 * 5 – 4 / 2
The answer should be 38.

d)                      10 / 5 * 30 / 15
The answer should be 4.

e)                      (8 + 4) * (7 – 3)
The answer should be 48.

 

TASK 4 (ONLY IF TIME PERMITS)

 

Did you know that Racket is the first programming language taught at the University of Waterloo?  Play around with it.  Look up a few example programs.  Have fun!