News for hackers. Stuff that matters.
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/