Live data from Hacker News

SICP in JavaScript

sourceacademy.org

81–90 of 126 posts

Re: SICP in JavaScript

#81

Earlier quoted context omitted.

They are, but you use ?-: instead of if-else

That still doesn't make all blocks expressions. In f# everything is an expression and it simplifies the language a lot. The last value in a block is considered the value "return" value of the whole block, which has the knockon effect of getting rid of most returns, allows you to check an if/else to return the same type and such. This also works in conjunction with the type inference, so you get an error when you try…

I understand. Scala is the same.

JavaScript has a limited form of that via the comma operator.

Re: SICP in JavaScript

#82
post #47
post #43

I think SICP and Scheme go together like horse and carriage, and neither Python, JavaScript or other "real world" languages should taint the insight gained from that wonderful pairing. Because Scheme - being a LISP - has the same syntax for code and data, metalinguistic abstraction is facilitated. Nobody should have to read through boilerplate code to dig up the core message of SICP. I took the Algorithmics I course…

I think SICP would be just peachy in Elixir, but I’m coming around to the notion that keeping functional programming for functional programmers is a form of professional neglect. Functional core, imperative wrapper is one of the few sane ways to build a large (Conway’s Law afflicted) system, and too many of my peers never studies SICP in school. They don’t even know the damage they do, and as we’ve learned in many, m…

Scheme is not a functional programming language. The last 2/3rds of sicp are possible only because you can mutate state.

Re: SICP in JavaScript

#83
post #75

Earlier quoted context omitted.

You know how people love to repeat that old saw about how computer science is no more about computers than astronomy is about telescopes (or whatever it is)? Well ironically (because it's the same exact people but this time on the other side of the misunderstanding) SICP is no more about scheme/lisp than computer science is about computers.

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.

Re: SICP in JavaScript

#84
post #68

I started this book with coworkers and it fell really flat. I haven't read the original, but knowing Scheme I could see why the book would be structured the way it is. In JavaScript, though, it really just doesn't work. The code is horribly non-idiomatic for JS, and because JS isn't actually Scheme the order of the concepts introduced doesn't make sense. When it does talk about JavaScript, it's condescending towards…

Thanks for the heads-up - I'm not going to bother with this piece then. Anyone with strong opinions about mainstream programming languages is automatically suspicious to me. I mean, I get it - plenty more elegant and better thought-out languages than JavaScript, with their practitioners pounding the floor, saying "it should have been me - not him!". But, ultimately, who can't write good code just because they're not…

Indeed which is why I write everything in machine code. What sort of elitist could possibly think this is a bad idea?

Re: SICP in JavaScript

#85
I took this course as "CS101" back in 2013 in NUS. I've also been coding in JS for the past 10 years.

Pretty happy with the content and the way it was taught.

Re: SICP in JavaScript

#87

Earlier quoted context omitted.

The 0 and 1 are completely unnecessary though in some of these. Example is_same_variable(exp, variable) ? 1 : 0 If is_same_variable returns a truthy value then return 1 else 0. We can remove that and it will still follow the same while also being more readable

It’s calculating the derivative. 0 and 1 aren’t used for their truthiness, but as values. d/dx x becomes 1 and d/dx y becomes 0 (the two cases, same variable and different variable).

JavaScript will coerc the types. 1+1 and true+true both = 2

Re: SICP in JavaScript

#88
post #73

Earlier quoted context omitted.

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…

Just for looksies. function deriv(exp,v){ //v = variable; if(is_number(exp) ){ return 0 } if(is_variable(exp){ return is_same_variable(exp,v) * 1 } if(is_sum(exp)){ a = deriv(addend(exp),v); return make_sum(a,a) } if(is_product(exp)){ m = multiplier(exp); c = multiplicand(exp); a = make_product(m,deriv(c,v)); b = make_product(deriv(m,v),c)); return make_sum(a,b) } return error(exp, "unknown expression type -- deriv")…

I'd possibly make it even more syntactically simple by removing the braces for one-line if statements. I know this can be a bit controversial, but for cases like this where the block consists only of a return statement, and where that statement fits on a single line (and where you have a formatter and a linter that will prevent you from writing indentation that doesn't match the semantics), it's very useful for removing visual clutter.

That said, this is pretty much how I'd write it, and seems a lot simpler than the heavily nested ternary (and I say that as a fan of nested ternaries!)

Re: SICP in JavaScript

#89
post #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?

>writing SCIP ...

Then you should probably SCIP SCIP.

Re: SICP in JavaScript

#90

Why does everything have to be Javascriptified? Scheme is a big part of the SICP experience and trying to do it in another language you are losing a lot. Do people learn Javascript when starting their web development career then refuse to learn anything else? Getting stuck with JS in the browser is an artifact of history and given how bad the language is we should avoid spreading it yet the opposite is happening. Fun…

>Funny for an industry that's allegedly about doing things as smart as possible the lowest common denominator dominates.

Yes.

The key word here is allegedly.

It's like how people rue the fact (a meme by now) that the (self-described) allegedly smartest minds in the world are desperately busy trying to, guess what, make people click more on ads(!), while largely ignoring ethics like giving people a choice about it, via opt-in rather than opt-out, confusing legalese in Privacy Policies and Terms and Conditions, fine print, etc.

Post reply on HN