Live data from Hacker News

SICP translated to JavaScript

comp.nus.edu.sg

81–90 of 116 posts

Re: SICP translated to JavaScript

#81
post #39

Earlier quoted context omitted.

For anything else, there are endless languages to choose from. The Americans have taken over and the Americans have, based on their own linguistic experience, decided most people can only handle one spoken language and one programming language. For some of us, we can handle six programming languages and be fine. For "average" people, they're lucky to get one programming language, so it was decided to fad-hype-hipster…

> Look on github for how many people write shell scripts in ruby because they don't know how bash works. You can find the same over-syntax'd-programming-environment-as-shell-script with node too. We're the exceptions. They can't handle the truth. As someone who has done this (and who currently works in C), I will say only that shell scripts translated to Ruby can be a lot easier to read and maintain than those writte…

You found the one exception. There's a fuzzy line when dealing with shell scripts.

If you're just iterating over a directory and checking some files, that's great shell script territory. If you're making a launcher script for another program to set the environment, check directories, fix permissions, and run pre-flight checks, that's great for shell script.

But, sometimes we end up with feature creep. You start out with "Well, this shell script just has to parse some CSV and insert into sqlite" then before you know it, it also has to check another pre-existing DB for redundancy checks or constraints, then you're 100 pages into the Advanced Bash-Scripting Guide trying to make Bash do something that would be a six liner in Perl 4.

The benefits of over-programming bash scripts is extensive portability though (if you make sure you aren't using features only in very late version of the shell).

Re: SICP translated to JavaScript

#82
post #66
post #7

Earlier quoted context omitted.

SICP uses Scheme, not Common Lisp. Scheme is a deliberately minimalist language, which is fairly accessible and easy to write your own implementation of. In fact, in SICP, you do that, a couple of times, writing first a Scheme interpreter, then extending it in various ways like adding logic programming capabilities, then you write a virtual machine and a compiler that compiles down to that virtual machine. JavaScript…

> Scheme is a deliberately minimalist language Ever looked at R6RS?

I'm not a big fan of R6RS, but it is still fairly minimalist. One of the good things that it did was divide the standard into a core language, and standard library built on top of the small core language. The core language eliminated many things from R5RS, but the standard library adds a lot more.

The main issues I have with R6RS are the library system (which I think is too complex, and it frustratingly adds an extra level of indentation as you need to wrap everything in one big expression), and some of the libraries in the standard library, like the I/O library, the Unicode library (which standardizes on such things as char-upcase and char-downcase, which are fairly useless in a Unicode context, without adding much that's actually useful).

R6RS is this kind of weird, awkward beast that's not sure what it's doing. It neither strips the language down to a minimal core, nor does it build up a comprehensive set of libraries containing all of the basics that people expect from standard libraries in a language these days.

Re: SICP translated to JavaScript

#83
post #68
post #38

Earlier quoted context omitted.

I know HOP. It depresses me how much of HOP is irrelevant in Python because they have proper iterators. And how few Perl programmers realize that these days the lack is a major omission in the language.

JavaScript doesn't have them either, until you include a functional toolchain library like Underscore. Does Perl have any similar library?

Not really. As ~btilly suggested in another post, perl really doesn't have anything like it. The closest thing that exists is using a code reference.

    sub new_iter {
      my $i = 0;
      return sub {$i++}
    }
    
    my $iter = new_iter();
    
    while(my $number = $iter->()) {
      say $number;
    }
This is of course a trivial example, but it does give a bit of an idea of the only way Perl has to be able to implement them, essentially anonymous functions and closures. This is useful, but it doesn't make it easy to take say a red-black tree, and iterate over the entire set of values in it (though with higher level languages like perl, you probably wouldn't implement much with a red-black tree, maybe a k-tree would be better?)

Re: SICP translated to JavaScript

#84
post #75
post #70

Earlier quoted context omitted.

Yeah, I'm with you on this. Aesthetically, I'm in the "ugh, Javascript" camp. But practically, I recognize that I should just get over this. For web stuff, I fully expect that I'll be writing everything in JS in a few years.

Considering it doesn't even support multiple core processors, and processors are only coming out with more and more cores, I doubt it. This is assuming you are actually doing something that requires performance. Check out Elixir or Go if you want something new that actually makes technical sense.

Or Clojure, which has a good concurrency story as well as compiles to javascript.

Re: SICP translated to JavaScript

#85
post #2

why, God, why?

Perhaps due to the increasing popularity of JavaScript and the decreasing accessibility or usage of Scheme.

> decreasing accessibility

Scheme is super-easy to set up these days.

Step 1: Download http://racket-lang.org/

Step 2: Follow the quick start guide: http://docs.racket-lang.org/quick/

Step 3: Click "Run"

No "click through Visual Studio's project setup" phase, no "how do I open the text editor from IDLE" phase, no "open a command prompt" it's all right there.

This makes the environment and the language perfect for beginner students.

Re: SICP translated to JavaScript

#86
post #57
post #46

Earlier quoted context omitted.

I'm a longtime perl user, and I don't know where my blind spots are. Are there any particular resources you would recommend for someone like me to get going quickly with python? In particular ones that specifically address the type of blind spot you mention?

The Python tutorial teaches the language fairly well: http://docs.python.org/2/tutorial/ The iterator section is http://docs.python.org/2/tutorial/classes.html#iterators . Here it is quickly. Suppose that an object has a __iter__ method which will return something with a next method that will, when it has exhausted the iterator, call StopIteration. Then all native looping constructs can loop over that object and it w…

s/call StopIteration/raise StopIteration/g

Re: SICP translated to JavaScript

#87
post #40

Earlier quoted context omitted.

I just want to meet one programmer who can work on server side code, client side code, etc who can't handle them being written in different languages. This fad just doesn't make any sense to me. Let's reinvent the wheel so we can have JSON literals instead of Ruby hashes!

I always thought this would be self-evident to people, but apparently not: The reason why I want to have Javascript on both the client and the server is so I can re-use code. My software has a fairly large chunk of code which is a gardening expert system. I'm hesitant to call it AI because it's so dumb, but it's along those lines. It knows things like "If you live in Phoenix and it's April, you should wait to plant y…

Fortunately, I think we're entering an era where JS can be a nearly transparent target language for translation from the languages of our choice, with things like asm.js and source maps. We're not quite there yet, but it definitely seems like where we're going.

Re: SICP translated to JavaScript

#88
post #48
post #29

Really sad to see that such amazing book that uses such nice language is now transformed to monster with JS. Why would you do that? Painful to see all that...

This will only serve to perpetuate the stupid meme that "Javascript is basically Scheme with curly braces and semicolons"

https://news.ycombinator.com/item?id=6069159

Re: SICP translated to JavaScript

#89
post #26

Earlier quoted context omitted.

Macros in js: http://sweetjs.org/ "Sweet.js brings the hygienic macros of languages like Scheme and Rust to JavaScript. Macros allow you to sweeten the syntax of JavaScript and craft the language you’ve always wanted."

> Use the sjs binary to compile your sweet.js code: That isn't JavaScript.

It's not in the core language but it fits in well with the JS ecosystem, and could be used for the purposes discussed here.
Post reply on HN