#lang racket ;; ----------------------------------------------------------------- ;; Questions about comments ;; ----------------------------------------------------------------- ; a single-line comment ;; a single-line comment #| a multi-line comment (fifth '(a b c d e)) (list-ref '(a b c d e) 3) (eq? 'x '(x)) that ends on the next line |# ;; ----------------------------------------------------------------- ;; (* 2 pi 1) ; for a circle with radius = 1 ;; (* 2 pi 10) ; for a circle with radius = 10 ;; (* 2 pi 14.1) ; for a circle with radius = 14.1 ;; def circumference(radius): ;; return 2 * pi * radius ;; (lambda (radius) ;; (* 2 pi radius)) (define circumference (lambda (radius) (* 2 pi radius))) ;; (define (circumference radius) ;; (* 2 pi radius)) ;; ----------------------------------------------------------------- (define square (lambda (x) (* x x))) (define sum-of-squares (lambda (x y) (+ (square x) (square y)))) ;; ----------------------------------------------------------------- (define list-of-students '((jerry 3.7 4.0 3.3 3.3 3.0 4.0) (elaine 4.0 3.7 3.7 3.0 3.3 3.7) (george 3.3 3.3 3.3 3.3 3.7 1.0) (cosmo 2.0 2.0 2.3 3.7 2.0 4.0))) ;; (average 3.7 4.0 3.3 3.3 3.0 4.0) (define compute-gpa (lambda (student) (apply average (rest student)))) (define sum-of-squares* ;; takes a list, not just two (lambda (list-of-numbers) (apply + (map square list-of-numbers)))) ;; ----------------------------------------------------------------- ;; This is a helper function I used in the compute-gpa example. ;; We will learn how to write procedures like average next time. ;; ----------------------------------------------------------------- (define average (lambda grades (/ (apply + grades) (length grades)))) ;; -----------------------------------------------------------------