Live data from Hacker News

SICP in JavaScript

sourceacademy.org

91–100 of 126 posts

Re: SICP in JavaScript

#91

Earlier quoted context omitted.

Nothing but when you nest them a whole bunch they are far harder to read and understand that if/else.

I frankly find it hard to imagine an expression form of if...else that's more readable than either the JS or Scheme versions of the code. In fact, I believe the problem with the JS example's readability is the formatting. Here's how I'd format the same code, and I find this quite readable: function deriv(exp, variable) { return is_number(exp) ? 0 : is_variable(exp) ? is_same_variable(exp, variable) ? 1 : 0 : is_sum(e…

Scala-style if expressions would be significatly more readable IMO (particularly if you also had the feature of allowing a block to be used as an expression).

    function deriv(exp, variable) {
        return if(is_number(exp))
              0
            else if(is_variable(exp))
              if(is_same_variable(exp, variable))
                1 
              else 
                0
            else if(is_sum(exp))
              make_sum(
               deriv(addend(exp), variable), 
               deriv(augend(exp), variable)
              )
            else if(is_product(exp))
              make_sum(
               make_product(multiplier(exp), deriv(multiplicand(exp), variable)), 
               make_product(deriv(multiplier(exp), variable), multiplicand(exp))
            )
            else error(exp, "unknown expression type -- deriv");
    }

Re: SICP in JavaScript

#92
post #75

Earlier quoted context omitted.

SICP is not about scheme or lisp, but its concepts are best understood in scheme in lisp. Just like the best way to understand what Saturn looks like is to look at it though a telescope. Sure you can use a spectrum scan or the output of a radio telescope, but it's really not the same as looking at in a telescope. Same thing here -- SICP just isn't the same if it's not in scheme or lisp.

> Just like the best way to understand what Saturn looks like is to look at it though a telescope. So then astronomy is about telescopes...? I'm happy to accept SICP is intimately related to lisp (which means it is less general than people claim) but just as long as we're consistent.

[deleted]

Re: SICP in JavaScript

#93
post #75

Earlier quoted context omitted.

SICP is not about scheme or lisp, but its concepts are best understood in scheme in lisp. Just like the best way to understand what Saturn looks like is to look at it though a telescope. Sure you can use a spectrum scan or the output of a radio telescope, but it's really not the same as looking at in a telescope. Same thing here -- SICP just isn't the same if it's not in scheme or lisp.

> Just like the best way to understand what Saturn looks like is to look at it though a telescope. So then astronomy is about telescopes...? I'm happy to accept SICP is intimately related to lisp (which means it is less general than people claim) but just as long as we're consistent.

> So then astronomy is about telescopes...?

No? I never said that. SICP teaches concepts, those concepts are better understood with lisp.

Astronomy teaches concepts, those concepts are better understood with telescopes.

In neither case is the subject about the tool, it's just better understood with the tool.

Re: SICP in JavaScript

#94
post #93

Earlier quoted context omitted.

> Just like the best way to understand what Saturn looks like is to look at it though a telescope. So then astronomy is about telescopes...? I'm happy to accept SICP is intimately related to lisp (which means it is less general than people claim) but just as long as we're consistent.

> So then astronomy is about telescopes...? No? I never said that. SICP teaches concepts, those concepts are better understood with lisp. Astronomy teaches concepts, those concepts are better understood with telescopes. In neither case is the subject about the tool, it's just better understood with the tool.

I just really think you should be ready to accept the full force of your words:

>Same thing here -- SICP just isn't the same if it's not in scheme or lisp.

That straight up reads like SICP and lisp are inseparable and that exactly means that SICP is not as general as people claim.

What we have here is unstoppable force meets immovable object (otherwise known as a contradiction). The resolution is simple: either SICP is valuable for the ideas, in which case renderings in js or python are fine, or SICP's value is diminished without lisp, in which case it's not actually about ideas but about the language of choice.

Can't have it both ways.

Re: SICP in JavaScript

#96
post #93

Earlier quoted context omitted.

> So then astronomy is about telescopes...? No? I never said that. SICP teaches concepts, those concepts are better understood with lisp. Astronomy teaches concepts, those concepts are better understood with telescopes. In neither case is the subject about the tool, it's just better understood with the tool.

I just really think you should be ready to accept the full force of your words: >Same thing here -- SICP just isn't the same if it's not in scheme or lisp. That straight up reads like SICP and lisp are inseparable and that exactly means that SICP is not as general as people claim. What we have here is unstoppable force meets immovable object (otherwise known as a contradiction). The resolution is simple: either SICP…

You have your causation backwards. SICP has valuable ideas in it. But those ideas are best understood using a particular tool.

You can use other tools to understand it, but it will be more work and you won't understand it as well.

Just like you could use a screwdriver to drive a nail into a board. But it will be easier and better understood if you use a hammer. The nail provides the same value either way.

Re: SICP in JavaScript

#97
post #86

If you want to work through SICP in Scheme, but don't have an easy way to run MIT Scheme, we made a compatibility thing, so you could do SICP using Racket (with your choice of editor/IDE, including DrRacket): https://docs.racket-lang.org/sicp-manual/

That's awesome! I'd rather use DrRacket than this Docker image I was using

https://hub.docker.com/r/stklos/stklos

Re: SICP in JavaScript

#98
post #64

Earlier quoted context omitted.

Right associative! It's just one of the many rites of passage for people working with PHP to get bitten by its left associative ternaries. Naked nested ternaries are deprecated now, but maybe one day, PHP can have right associative ternaries.

Except when it's not, like in perl.

Not sure what you mean, but ternaries are right-associative in Perl just like most other languages. PHP is the odd one out.

Re: SICP in JavaScript

#99
post #77

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) ? m…

Uh oh. That's like the original Numerical Recipes in C. All the arrays had their first value as 1, instead of 0. It was a conversion from FORTRAN, where arrays really did start at 1. The Numerical Recipes authors provided an array allocator which generated an address offset before the beginning of the array to make that work. It was awful. I rewrote the algorithms I needed with sane layout. The whole point of SCIP wa…

No. If you think that's the whole point, you missed the point.

Mathematical beauty was one of the ways to make the point, but far from the most important.

As a footnote, one of the changes which happened since publication is the victory of functional. Note that both JavaScript and Python now embody many of the principles, design patterns, and best practices from SICP.

As a second footnote, you're right: SCIP reads better than SICP. "Skippity do da..." (and if you want a third footnote, I know in the original it's zippity, but that's how kids in MY elementary school sang it, so to me, it will always be skippity"

Re: SICP in JavaScript

#100
post #14

What I loved most about my class based on SICP was that I learned a whole new way to reason about code, and that came from using Scheme. They changed the intro class at Berkeley to use Python a while back, when the folks who knew lisp/scheme retired, and I think it made the class much worse. This is really the death knell of SICP isn't it?

[deleted]
Post reply on HN