~~~~Main
Home
Contact

~~~~Projects
vee
Computer Merit Badge
PatchLodge.com
Projects Summary

~~~~My Bookmarks
ACM@LSU CS Resources
Programming
Operating Systems
Computer Architecture
Databases

 

Thu Sep 20 12:50:33 EDT 2007

onto recursive interators in Perl

--

I  am still getting the hang of things, but here is an example of
implementing recursion using the iterator paradigm.  I  am  going
down  this route because I'd like to implement a not-so-straight-
forward recursive function (depth first search of a graph) as  an
iterator.

Here is my latest:

  1 #!/usr/bin/env perl
  2 use strict;
  3 use warnings;
  4
  5 sub recurse {
  6   my $max = shift;
  7   my $number = shift;
  8   if ($number < $max) {
  9     return sub { return recurse($max,$number+1); }
 10   } else {
 11     return sub { print "done"; };
 12   }
 13 }
 14
 15 my $next = recurse(3,0);
 16 $next = $next->();
 17 $next = $next->();
 18 $next = $next->();
 19 $next = $next->();
 20
 21 1;


--
Powered by vee
Copyright © 2006-2010
FreeBSD
Perl
Qore