Due: Thursday 10/10 10:00am
Submission name: work13.rkt
Part 0
Copy the following code into the definitions pane of DrRacket and run it. You should run it multiple times. Then answer the questions below:
(define a (list 51 2 21 42 46 20))
(display "useful output for questions 1-4\n")
a
(first a)
(rest a)
(define b (rest a))
(first b)
(display "useful output for questions 5-6\n")
(build-list 5 sqrt)
(build-list 5 (lambda (x) (* x x)))
(display "useful output for questions 7-9\n")
(random)
(random 2)
(random 5 10)
Questions
Add a comment block #| ... |#
and answer the following questions inside it.
- What does
first
do? - What does
rest
do? - For this question, write new code at the end of the provided code. Using the list
a
as defined, how would you return the list starting at the number 21? - For this question, write new code at the end of the provided code. Using the list
a
as defined, how would you return the number21
? - What does
build-list
do? - For this question, write new code at the end of the provided code. Write a line of racket code that uses
build-list
to create a list of the first 5 perfect cubes. - What does
random
do if you give it no arguments? - What does
random
do if you give it one argument? - What does
random
do if you give it 2 arguments? - For this question, write new code at the end of the provided code. Write a line of racket code that uses
build-list
andrandom
to make a list of 10 random integers in the range [10, 20) (this includes 10 but excludes 20).