2014-11-03 lab+HW

posted Nov 3, 2014, 4:09 AM by Samuel Konstantinovich   [ updated Nov 3, 2014, 5:37 AM ]
Goal: Selecting specific or random elements of a list.

Do Now:
1. Log in and run DrRacket.
2. Switch your racket to the 'Pretty Big' language.
3. Test the (random x) command like: (random 10) 
-Through experimentation: Determine the range of possible values of the (random x) command.
-On paper:
  -What is the range of values of (random x) in terms of x? 
  -How would a random command be useful to us when writing a program?

Consider that we index elements of a list starting at 0:
  0th 1st  2nd   3rd 
'(the best thing ever)
So the number at the 1st index is 'best'

   0  1  2  3  4       (these are the indices)   
 '(1  3  9  4  5)
The number in the 3rd index is 4.

note: indices is the plural of index

Write a function (getNth L n) that accepts a list L, and an index n (always an integer), and returns the top level element of the list at index n. Assume n is a non-negative integer.
Read/Answer before you write anything:
-How should this function work when the list is not long enough?
-Should this function work with sublists? What would happen if it does?
-What should your function's output look like?

Part 2:
Now that You have the getNth function:
Write a function (getRandomTopLevelElement L)  that returns one of the top level elements of the list.
Read/Answer before you write anything: 
-You have worked on a do now that is relevant to your work right now. 
-You need to test your code with your own test cases, What will you test with and what should happen?

How might we use this particular function?
Write down 3 creative/interesting/fun programs you might be able to write using this function.

Part 3: Where are we going with this?

0. Complete the lab!
On the computer make an interesting list of :
1. singular nouns 
2. verbs  (runs, walks, talks ... etc)
3. adjectives
(at least 20 interesting words of each category)