;;; ---------------------------- ;;; CMPU-181, Spring 2013 ;;; Code from class ;;; Feb. 6, 2013 ;;; ---------------------------- ;;; Defining some global variables (define xyz (+ 2 100)) (define listy '(1 2 3 4 5)) (define cube (lambda (x) (* x x x))) ;;; FACTY ;;; ------------------------------------ ;;; INPUT: N, a positive integer ;;; OUTPUT: N!, the factorial of N (i.e., 1*2*3*...*n) (define facty (lambda (n) (if (= n 1) ;; Base Case: N = 1 1 ;; Recursive Case: N > 1 (* n (facty (- n 1)))))) ;;; PRINT-N-DASHES ;;; ----------------------------------- ;;; INPUT: N, a non-negative integer ;;; OUTPUT: None ;;; SIDE EFFECT: Prints out N dashes in the interactions window, ;;; followed by a newline character. (define print-n-dashes (lambda (n) (cond ;; Base Case: N = 0 ((= n 0) ;; Print the "newline" character (newline)) ;; Recursive Case: N > 0 (else ;; Print one dash... (printf "-") ;; And let the recursive function call print the rest of them! (print-n-dashes (- n 1))))))