(define (bob x) ;;what is bob? what data types can x be? (= (remainder x 2) 0))when you could write this:
(define (even? n) ;;even? returns a boolean and it asks if an (= (remainder n 2) 0)) ;;integer (n) is evenand don't write this:
(define (short-word word) (< (count word) 3))when you could write this:
(define (short-word? wd) (< (count wd) 3))
(define (sent-max num-sent) (cond ((empty? num-sent) '()) ;;You don't want this line ((empty? (bf num-sent)) (first num-sent)) (else (max (first num-sent) (sent-max (bf num-sent))))))Why is this bad? If you do something silly like (+ (sent-max '()) 4), you get an error from +, not sent-max!
(cond ((and (>= x 4) (even? y)) 'yes) ((and (>= x 4) (not (even? y))) 'no) ;;if you get here, y .... ;;can't be even! (cond ((and (>= x 4) (even? y)) 'yes) ((>= x 4) 'no) ;;this is fine ....
(else (+ 4 7) (+ x y)) ;;you never see the results of (+ 4 7)!For that matter, don't write more than one expression without connecting them somehow.
(define (badidea1 x) (+ x 9) (* 7 x)) ;;you do the (+ x 9), but it doesn't matter to ;;badidea1
(if (= x 8) 'absolutely) ;;what do if x isn't equal to 8? If x is ;; always equal to 8, why have the if?
;;;;;;;;;;;;;;;;;;;;; procedure name here ;;INPUTS: give the placeholder names and what data types they can be ;;REQUIRES: anything else about the variables (all positive, for ;; example) ;;RETURNS: tell what the procedure returns ;;EXAMPLE: give at least one example: show a procedure call and ;; tell what it returns. It never hurts to have a couple ;; of these. If your procedure returns several very different kinds ;; of data, include one test that shows each kind. If your procedure ;; returns only #t or #f, ;; show a test that returns #t and a test ;; that returns #f ;;
(define (quadratic-rule a b c) (se (/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* a 2)) (/ (- (- b) (sqrt (- (* b b) (* 4 a c)))) (* a 2)))))Do this instead:
(define (quadratic-rule a b c) (se (/ (+ (- b) ;;add -b (sqrt (- (* b b) to sqrt(b^2 - 4ac) (* 4 a c)))) (* a 2)) ;;end of the first term (/ (- (- b) (sqrt (- (* b b) ; (* 4 a c)))) (* a 2)))) ;;end of the second term
(define (badidea3 x) (cond ((word? x) (sentence 'word x)) ((sentence? x) x)))What if you call badidea3 with #t? Do this instead:
(define (betteridea x) (cond ((word? x) (sentence 'word x)) ((sentence? x) x) (else (se '(oops! what is) x '?))))