C311 Fall 1996 -- Programming Languages

Scheme Quizette


  1. Write the procedure square that takes a number and returns the square of the number.
    > (square 1)
    1
    > (square 9)
    81
         
    
    
    
    
    
    
    
    
    
  2. Write the procedure member? that takes an atom a and a list ls and returns #t if a is in ls and #f otherwise.
    > (member? (quote c) (quote (s c h e m e)))
    #t     
    > (member? (quote basic) (quote (s c h e m e)))
    #f     
    
    
    
    
    
    
    
    
    
    
    
    
  3. Write the procedure duplicate that takes a number n and an atom a and returns a list containing only n occurrences of a.
    > (duplicate 3 'foo)
    (foo foo foo)
    > (duplicate 0 'foo)
    ()
    
    
    
    
    
    
    
    
    
    
    


Chris Haynes / chaynes@indiana.edu