[ prog / sol / mona ]

prog


SICP using JavaScript

1 2022-01-22 01:21

A new version of SICP will be published by MIT Press. It will be a JavaScript edition. Long live JavaScript!

https://mitpress.mit.edu/books/structure-and-interpretation-computer-programs-1

2 2022-01-22 04:49 *

Javascript is best lisp.

3 2022-01-22 04:55

What vile rot.

4 2022-01-22 08:55

I think this was discussed here before but I can't find the thread.

5 2022-01-22 11:41

I've read the headline somewhere but I didn't understand it was a new official edition.

6 2022-01-22 13:15

the great reset was real
they tried to warn us
the end is near

7 2022-01-22 14:11 *

Previous discussion: https://textboard.org/prog/281/10-12

8 2022-01-22 14:41

Why are people so afraid of learning a new programming language? Scheme is tiny and you don't even need to know all of it for SICP. But people would rather translate SICP into JavaScript than learn a bit of Scheme? No wonder most programmers these days are clueless code monkeys who can't get past cargo cult programming.

9 2022-01-23 05:10

Will this cause a long-term decline of Scheme? There will probably be less people exposed to Scheme through SICP if the JavaScript edition eclipses the Scheme edition.

10 2022-01-23 09:41

The previous edition was Python edition, so no it will not.

11 2022-01-23 22:06

Scheme will live on in JavaScript.

12 2022-01-24 07:22 *

>>11
Excuse me javascript is a lisp not a scheme.

13 2022-01-31 06:39

This will of course generate a lot of vile hatred from the closed-minded conservative Scheme reactionaries who cannot imagine a world where Scheme loses its status as the sole liturgical language of SICP.

JavaScript has won. The victors will rewrite history, a history where Scheme was heavily inspired by JavaScript. However, not all hope is lost for the Schemers. They will be enrolled in JavaScript education camps, where they will finally get to admire the truth and beauty of JavaScript as the foundational programming language of the world.

14 2022-02-03 06:17

This will cause a schism and spark a holy war between the SICP/Scheme sect and the SICP/JavaScript sect.

15 2022-02-03 09:42

What about SICP/Python sect?

16 2022-02-03 12:12

>>15
JavaScript is more Pythoinic.

17 2022-02-04 03:12

Using these, and the primitive predicate number?, which identifies numbers, we can express the differentiation rules as the following procedure:

(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))))

[...]

Using these, and the primitive predicate is_number, which identifies numbers, we can express the differentiation rules as the following function:

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");
}
18 2022-02-04 04:12

>>17
As you can see, the JavaScript version is clearer and more relatable than the esoteric Scheme version.

19


VIP:

do not edit these