Scheme Exercises
back to exercise list
previous next
Group: Exercise: 14/48
Two-part function:
A function that has two parts, deciding between two alternative answers.
Create a function two(x) that has the value 12 when x <= 3, but has the value 4x when x > 3. For instance. two(1) = 12, but two(10) = 40.
The function has been defined above using mathematicians' notation, like two(x) In Racket, the equivalent definition of the function will be written as (define (two x ) implementation-code-here) except with useful code replacing "implementation-code-here". The function can also be defined using the equivalent lambda notation. The calls to the function will be written in Racket like (two 1) (two 10)
|