Warning Warning Warning:
  I'm just attempting to explain how these things would be done
  if you were using Set::Infinite API.

>   while ( my $dt = $dt_iterator->next( sort => 'asc' ) )

- first() returns "head and tail" of a set, as if it were a list of
subsets:

    while ( ($dt, $dt_iterator) = $dt_iterator->first )
   
> > while (<$dt_set>) { ... }

- list() builds a list of subsets. It doesn't work for unbounded sets,
of course.

    while ( $dt_set->list )

> implementing sorting as an object attribute (as opposed to method
> parameter) 

- Lists of DateTime objects are sortable. Sets are not.
However, lists of subsets are sortable.

> > > For what I hope are obvious
> > > reasons, callbacks will have to guarantee that given a datetime X, they
> > > always produce a datetime >X _or_ <X.  If it were both, there'd be no way
> > > to check whether Y was a member of an unbounded set.  This will be a big
> > > fat warning in the docs.

- Set::Infinite is a "set equation solver". I doesn't have this
restriction. 

> > I don't really understand how these callbacks are supposed to work.
> > How does it know when it's generated the appropriate datetime?  I mean
> > if you have a set that's supposed to represent all of the saturdays
> > forever starting with next saturday, how do you tell if Jan 1, 2537 is
> > in the set?

   $bool = $saturdays->intersects( $jan_1_2537 );

>  sub generate_each_saturday
>  {
>      my $dt = shift; # highest date current known to be in set
> 
>      my $add_days = ... # how many days until next Saturday?
>                         # I am bad with algorithms
> 
>      return $dt + DateTime::Duration->new( days => $add_days );
>  }

- This is how Set::Infinite would do it:

First, quantize() splits the period into weeks; 
then, offset() sets the weekday (I guess "6" is saturday, I didn't check
this).

  # $period is (-Inf..Inf) or whatever
  $saturdays = $period->quantize( unit=>'weeks' )->offset( unit=>'days',
value=>[6,7] );
 
I'll do it again, slowly:

  $period = Set::Infinite::new(-$inf..$inf);   # "forever"
  $weeks = $period->quantize( unit=>'weeks' ); # "all weeks, forever"
  $saturdays = $weeks->offset( unit=>'days', value=>[6,7] );  # "all
saturdays, forever"

  $is_saturday = $saturdays->intersects( $jan_1_2537 );

or

  $is_saturday = $jan_1_2537->intersects( $saturdays );

> > What happens if you remove an element that hasn't been generated yet?

- it will be removed :)

  $almost_all_saturdays = $saturdays->complement( $jan_1_2537 );

> > "certain types of sets"? A set is a set is a set.  Or should be.  How
> > is a user to know what can and can't be done?

- right.
 
> There's certain things you just can't do with most (all?) unbounded sets.
> For example, if you have and unbounded sets, which has its recurrence
> specified through a generator callback, there is absolutely no way to ever
> determine whether it intersects with another set, because you could call
> the generator an infinite number of times, find no matches, and _still_
> not know if the next call will return a match.

- Finding out if an unbounded set contains another unbounded set might 
be possible or not. 

Operations with one bounded set and one unbounded set are (almost?) 
always possible.

> What is impossible will be documented.

:)

- Fl�vio S. Glock

Reply via email to