Subject: | difference() when different alphabets |
Date: | Sat, 20 Aug 2016 12:36:05 +1000 |
To: | bug-FLAT [...] rt.cpan.org |
From: | Kevin Ryde <user42_kevin [...] yahoo.com.au> |
With FLAT 0.9.1 I was tricked by difference() on some strings like
use strict;
use FLAT;
my $f = FLAT::Regex->new('foo | bar')->as_dfa;
my $t = FLAT::Regex->new('foo ')->as_dfa;
$f = $f->difference($t);
print $f->is_empty ? "empty\n" : "not empty\n";
print $f->contains('bar') ? "contain bar\n" : "no contains bar\n";
This prints "empty" whereas at first I thought foo+bar subtract foo
might leave bar. I see this happens because the alphabet in $f and $t
are not the same.
Maybe the docs could caution that difference() should have alphabet of
$t at least as big as $f, otherwise the complement() part means you lose
the extras in $f.
Maybe another flavour of difference, with a new method name, could allow
for symbols of $f not appearing in $t. Dunno exactly how, extend the
alphabet of $t or something.