2006/4/4, Larry Wall <[EMAIL PROTECTED]>:
> But this is all based on enumerated sets.  Oddly missing are any
> Sets that are defined by rule.  That would presumably take closures,
> though I suppose one can attempt to enumerate the closures that have
> to hold true and autothread through the calls to those closures...
>
> Can Russel be far behind?  :-)

This is in ext/Recurrence:

        use Recurrence;

        # all integer numbers
        $universe = Recurrence.new(
            closure_next =>     sub { $_ + 1 },
            closure_previous => sub { $_ - 1 },
            :is_universe(1) );

        # all even integers
        $even_numbers = Recurrence.new(
            closure_next =>     sub { 2 * int( $_ / 2 ) + 2     },
            closure_previous => sub { 2 * int( ( $_ - 1 ) / 2 ) },
            universe => $universe );

        # all odd integers
        $odd_numbers = $even_numbers.complement;

        # all non-zero integers
        $non_zero = Recurrence.new(
            closure_next =>        sub ($x) { $x == -1 ??  1 !! $x + 1 },
            closure_previous =>    sub ($x) { $x ==  1 ?? -1 !! $x - 1 },
            complement_next =>     sub ($x) { $x < 0   ??  0 !!    Inf },
            complement_previous => sub ($x) { $x > 0   ??  0 !!   -Inf },
            universe => $universe );

- Flavio S. Glock

Reply via email to