Comment

Comment by LiamPowell

It seems like they have attempted to write scheme using JavaScript syntax to avoid having to make any significant changes to the non-code sections of the book.

Here is an excerpt, it's not good:

    function deriv(exp, variable) {
        return is_number(exp)
               ? 0
               : is_variable(exp)
               ? is_same_variable(exp, variable) ? 1 : 0
               : is_sum(exp)
               ? make_sum(deriv(addend(exp), variable),
                          deriv(augend(exp), variable))
               : is_product(exp)
               ? make_sum(make_product(multiplier(exp),
                                       deriv(multiplicand(exp),
                                             variable)),
                          make_product(deriv(multiplier(exp),
                                             variable),
                                       multiplicand(exp)))
               : error(exp, "unknown expression type -- deriv");
    }
Here is the original code:

    (define (deriv exp var)
      (cond ((number? exp) 0)
            ((variable? exp)
             (if (same-variable? exp var) 1 0))
            ((sum? exp)
             (make-sum (deriv (addend exp) var)
                       (deriv (augend exp) var)))
            ((product? exp)
             (make-sum
               (make-product (multiplier exp)
                             (deriv (multiplicand exp) var))
               (make-product (deriv (multiplier exp) var)
                             (multiplicand exp))))
            (else
             (error "unknown expression type -- DERIV" exp))))
parent LiamPowell 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton