Chapter 2: Expressions inside Expressions inside Expressions
In the previous chapter, you have learned to compose simple expressions in computer programming language.
In this chapter, you are going to learn how to compose nested expressions: expressions inside expressions inside expressions…
Nested expressions are like russian dolls: one expression contains an expression that contains an expression that contains an expression that contains…
You are probably asking yourself how could we have an expression that contains an expression?
Well, as an example, Let’s compose a nested expression that adds
4 and multiply the result by
For that, we are going to use again the 3 steps of an expression that we introduced in previous chapter:
First, you need to tell the computer that you want it to execute something. For that you use the parenthesis:
(). The computer will execute for you the content of the parenthesis.
Then, you need to tell the computer what
operationyou want it to execute: in our case, the operation is the multiplication.
Finally, you need to tell the computer what are the details of the
operands. In our case, the
(+ 3 4)and
Combining all of that, we get:
(* (+ 3 4) 5)
Congratulations! This is your first nested expression.
Now, try to use more
operands: for instance, you could type
(* (+ 3 4) 5 6 8).
If you are having difficulties with one exercise, read again the details of the 3 steps of an expression.
A. add 10 to 12 and multiply the result by 3
B. add 7 to 9 and multiply the result by 5
C. multiply 7 and 9 and add 6 to the result
D. multiply 7 and 9 and add 6 and 9 to the result
E. add 7 to 9 and multiply the result by 5 and 3
F. add 7 to 9 and multiply the result by
(+ 3 8 9)
Here are the solutions:
Send us a screenshot with your programs to email@example.com.