The following exercises are by no means comprehensive, but meant to give you some practice putting together the concepts from this section.
Consider the following functions,
; even? : number -> boolean ; returns a boolean indicating whether a number is even > (even? 4) #true > (even? 5) #false ; and : boolean, boolean -> boolean ; returns true if and only if both arguments are true > (and true true) #true > (and true false) #false > (and false false) #false
Use these two functions to write an expression that returns whether
10 are both even.
As you know, the
+ function works with any number of numbers, not just two of them:
> (+ 1 2 3 4 5 6) 21
For this exercise, let's pretend we can't do that.
Write an expression to sum the integers 1 through 6, subject to the following constraint:
- Whenever you use
+, you can only add two numbers at a time.
Of course, you can use
+ itself as many times as you want.
Write an expression to convert a number to a string, then convert the string to an image of text.
You may need to search the
2htdp/image documentation for the
Consider the following expression:
(and (odd? 19) (> 4 (* (string-length "foo") 2)))
- What is the return type of this expression? How do you know?
- There are five function calls in this expression. In what order are they called?
- What does this expression simplify to?
Check your answers using the DrRacket stepper. Then try writing your own complicated expression.