On Wed, 15 Jan 2003, Jonathan Scott Duff wrote:
> On Wed, Jan 15, 2003 at 01:20:48PM -0600, Dave Rolsky wrote:
> > - iterate over sorted members. Again, this is not a set operation, but
> > for convenience we will offer something like
> >
> > while ( my $dt = $dt_set->next( sort => 'asc' ) )
Actually, that's a typo on my part. It should be:
while ( my $dt = $dt_iterator->next( sort => 'asc' ) )
> I hope for
>
> $dt_set->sort('asc');
> while (<$dt_set>) { ... }
But yes, implementing sorting as an object attribute (as opposed to method
parameter) makes sense. Tied filehandle? I don't think so.
But I do want to stress that you cannot sort a set. Sets do not have
ordering, thus they cannot be sorted, at least in theory.
> > Another side note on recurrence: we will allow people to specify
> > recurring datetime generators via callbacks. 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.
>
> Or you could specify that all generated times that are beyond the
> bounds are mapped to the appropriate endpoint. Still, caveat
> scriptor.
Come again? I don't undestand what you're suggesting
> > # unbounded (on "right") - $dt_object & greater datetimes
> > my $dt_set = DateTime::Set->new( start => $dt_object,
> > recurrence_callback => \&generate );
> >
> > # unbounded (on "left) - $dt_object & less
> > my $dt_set = DateTime::Set->new( end => $dt_object,
> > recurrence_callback => \&generate );
>
> 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?
The callbacks will work like this:
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 );
}
> Callbacks make sense for a bounded set, but I'm having trouble
> wrapping my mind around the unbounded versions.
They just never stop getting called.
> > $dt_set->remove(); # same as above
>
> What happens if you remove an element that hasn't been generated yet?
Keep of track of the fact that it should be ignore if it is found to be in
the set.
> > As the comments above indicate, certain operations are not possible with
> > certain types of sets.
>
> "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?
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.
Since ->contains() is just ->intersects() with a 1-element set as its
parameter, the same problem applies.
But you can create the union of two sets, one or both of which is bounded.
Attempts to do impossible things will throw/return an appropriate error.
What is impossible will be documented.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/