;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname oct12-dist-part1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) (require "student-extras.rkt") (define (root a b c) (/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a))) ;(check-expect (root 1 2 1) -1) ;(check-expect (root 2 5 3) -1) ; if ax^2 + bx + c = 0, what is x? ; Use the quadratic formula! ; ; x = (-b + sqrt(b^2 - 4ac)) / 2a (we'll ignore the - branch of the +/-) (define discriminant 999) (define two 2) (define (root2 a b c) (let* {[discriminant (- (* b b) (* 4 a c))] [numerator (+ (- b) (sqrt discriminant))] [denominator (* two a)] } (/ numerator denominator))) ; In `let`, the scope of the new identifiers is the let's body-expression (only). ; In `let*`, the scope of the new identifiers is ALL FOLLOWING RIGHT-HAND-SIDES, ; and the let's body-expression. ; let* is equivalent to nested-lets; ; in fact, internally it is syntactic sugar for just that. ; ; "syntactic sugar" -- a language feature(syntax) which internally ; gets re-written as other existing syntax. (check-expect (root2 1 2 1) -1) (check-expect (root2 2 5 3) -1)