Material to Understand

Exercises

  1. Set a variable named year to 2000.
  2. Write a one parameter function named add-one that adds 1 to the number passed in.
  3. Test the above function with the call (add-one year). Is year's value 2000 after the call? Explain.
  4. (Problem 3-5.) Write a function called palindromize that takes a list as its argument and returns a palindrome that is twice as long as the argument. For example, (palindromize '(I love AI)) should return '(I love AI AI love I).
  5. Use let in a function that calculates the two roots of a quadratic equation. For example, (roots 1 5 6) could return '(-2 -3). Develop this function in a file and load it into the CLISP Interpreter. Once the function works, compile it to ensure that there are no warnings. Run the compiled version.
  6. Comment the above function appropriately and then have John take a look at it. Here is a model:
        
        ;; =================================== 
        ;;            John Paxton 
        ;;              CS 436 
        ;;         September 3, 2004 
        ;; ----------------------------------- 
        ;; Brief overview of this file's contents. 
        ;; =================================== 
    
        ;; ----------------------------------- 
        ;; KEEP-ENDS 
        ;; ----------------------------------- 
        ;; Return a list of the first and last
        ;; top level items. 
        ;; ----------------------------------- 
        ;; PARAMETERS 
        ;;  alist: an arbitrary list 
        ;; ----------------------------------- 
       
        (defun keep-ends ( alist ) 
          (cons (first alist) (last alist)) 
        ) 
    
  7. Write a function where the use of let causes the function to perform differently than the use of let*.