News for hackers. Stuff that matters.
Re:SICP translated to JavaScript by neilk on Saturday September 14, 2013 @12:09PM (#6386028)
Obvious objections - JS has no tail call elimination, no macros, and state-changing is managed with entirely different conventions in Scheme. Also the conceit of SICP (not really justified) is that they don't have to teach you syntax, because homoiconicity. Still, I think it's a worthy pursuit to try to bring the insights of this book to a wider audience.

Side note: the navigation is really irritating. The back button only works sometimes, because it's replacing content without doing some kind of pushState. So you have to hunt for links.

Another side note: Sean Burke and Piers Cawley have ported some of mjd's excellent book Higher-Order Perl to JavaScript. This might be even better, because both Perl and JS have C-like syntax hiding some impressive functional capabilities. I wish someone would finish that, but I guess few people even know about HOP, these days.

http://interglacial.com/hoj/hoj.html

http://www.bofh.org.uk/2010/11/18/higher-order-javascript

Re:SICP translated to JavaScript by btilly on Saturday September 14, 2013 @01:24PM (#6386307)
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.

Re:SICP translated to JavaScript by Sukotto on Saturday September 14, 2013 @01:46PM (#6386397)
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?

Re:SICP translated to JavaScript by btilly on Saturday September 14, 2013 @02:37PM (#6386577)
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 will just work.

If you call a function that internally calls yield and nowhere calls return, then you get back a generator, which is an object with those methods.

There is also syntax to construct such generators inline without even an explicit function.

All of the closure based looping stuff in HOP which supports potentially infinite streams? It is all built in!

Re:SICP translated to JavaScript by gonnakillme on Saturday September 14, 2013 @07:55PM (#6387588)
s/call StopIteration/raise StopIteration/g
Re:SICP translated to JavaScript by StavrosK on Saturday September 14, 2013 @11:53PM (#6388068)
I wrote a tutorial a while ago exactly for this purpose:

http://www.stavros.io/tutorials/python/

Re:SICP translated to JavaScript by xiaoma on Saturday September 14, 2013 @03:41PM (#6386804)
JavaScript doesn't have them either, until you include a functional toolchain library like Underscore. Does Perl have any similar library?
Re:SICP translated to JavaScript by neilk on Saturday September 14, 2013 @04:46PM (#6387017)
JS 1.7, already available in some browsers and bleeding edge Node, has iterators and generators.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...

Re:SICP translated to JavaScript by cytzol on Saturday September 14, 2013 @04:17PM (#6386924)
Re:SICP translated to JavaScript by simcop2387 on Saturday September 14, 2013 @05:25PM (#6387116)
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 by draegtun on Sunday September 15, 2013 @05:58AM (#6388600)
There are plenty of iterator/generator libraries on CPAN. My personal favourite is Coro::Generator - https://metacpan.org/module/Coro::Generator

Re: Underscore... there is a Perl port - http://vti.github.io/underscore-perl/

Re:SICP translated to JavaScript by jessep on Saturday September 14, 2013 @12:41PM (#6386152)
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."

Re:SICP translated to JavaScript by archgoon on Saturday September 14, 2013 @01:19PM (#6386282)
> Use the sjs binary to compile your sweet.js code:

That isn't JavaScript.

Re:SICP translated to JavaScript by azakai on Saturday September 14, 2013 @09:24PM (#6387807)
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.
Re:SICP translated to JavaScript by mistercow on Saturday September 14, 2013 @02:10PM (#6386485)
>JS has no tail call elimination

Apparently this is changing with ES6.

Re:SICP translated to JavaScript by zodiac on Sunday September 15, 2013 @08:45AM (#6388909)
It might be worth noting that this class (CS1101S in NUS) stops at chapter 3 of SICP. I took the previous scheme version of the class.

Btw, I'm curious as to why the HOJ book didn't get taken down? I checked and the HOP book is not released under a license that allows for derivative works. I'm curious because I've made an interactive version of SICP (using scheme) and I can't find any other books to do this to because no one releases books under permissive enough licenses.

Re:SICP translated to JavaScript by officialjunk on Saturday September 14, 2013 @12:29PM (#6386103)
tail call elimination can be implemented in javascript: http://raganwald.com/2013/03/28/trampolines-in-javascript.ht...
Re:SICP translated to JavaScript by jfb on Saturday September 14, 2013 @02:46PM (#6386607)
Trampolines are a solution to the same problem that tail-call elimination solves; they're not transparent to the programmer.
Re:SICP translated to JavaScript by 59nadir on Sunday September 15, 2013 @11:50PM (#6391522)
> Also the conceit of SICP (not really justified) is that they don't have to teach you syntax, because homoiconicity.

What syntax is there to teach?