Live data from Hacker News

SICP in JavaScript

sourceacademy.org

1–10 of 126 posts

Re: SICP in JavaScript

#2
On my phone I just get a drawing of an alien spaceship? I tried loading it through an archive (and I do get the front page of a web book) but none of the links work there.

Re: SICP in JavaScript

#3
I might be wrong, but I feel like writing SCIP on JS is like "Sustainable Energy using Oil."

Not quite the right analogy... JS isn't as bad as Oil. But you get the idea...

Kinda... don't make sense?

Re: SICP in JavaScript

#5
post #2

On my phone I just get a drawing of an alien spaceship? I tried loading it through an archive (and I do get the front page of a web book) but none of the links work there.

seems to be some sort of loader, I got that but then it turned to the SICP in JavaScript cover - I did scroll so maybe it was the onScroll event.

Re: SICP in JavaScript

#8
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))))
Post reply on HN