X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FSub%2FNary.pm;h=4a02bc2524b6c397f618e568f1870fbd3b57f16f;hb=2d8aec84852aa584b41d7cfce42088fec7ca8582;hp=3a0b00097b305393648f75290be32933e4d13f78;hpb=94abb82a3fbe010a38413500797bbdb4d373e016;p=perl%2Fmodules%2FSub-Nary.git diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 3a0b000..4a02bc2 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -42,7 +42,7 @@ This module uses the L framework to walk into subroutines and try to guess ho The usual constructor. Currently takes no argument. -=head2 C +=head2 C Takes a code reference to a named or anonymous subroutine, and returns a hash reference whose keys are the possible numbers of returning scalars, and the corresponding values the "probability" to get them. The special key C<'list'> is used to denote a possibly infinite number of returned arguments. The return value hence would look at @@ -102,7 +102,7 @@ returns C<3> or C<4> arguments with probability C<1/2> ; and never returns C<1> argument but returns C<2> with probability C<1/2 * 1/2 = 1/4>, C<3> with probability C<1/2 * 1/2 + 1/2 * 1/2 = 1/2> and C<4> with probability C<1/4> too. -=item * The C<'list'> state is absorbant in regard of all the other ones. +=item * The C state is absorbing in regard of all the other ones. This is just a pedantic way to say that "list + fixed length = list". That's why @@ -112,7 +112,8 @@ That's why } is considered as always returning an unbounded list. -The convolution law also does not behave the same when C elements are involved : in the following example, + +Also, the convolution law does not behave the same when C elements are involved : in the following example, sub oneorlist { if (rand < 0.1) { @@ -202,11 +203,16 @@ $ops{$_} = 0 for qw/stub nextstate/; $ops{$_} = 1 for qw/padsv/; $ops{$_} = 'list' for qw/padav/; $ops{$_} = 'list' for qw/padhv rv2hv/; -$ops{$_} = 'list' for qw/padany flip match/; +$ops{$_} = 'list' for qw/padany flip match entereval readline/; +$ops{stat} = { 0 => 0.5, 13 => 0.5 }; +$ops{caller} = sub { my @a = caller 0; scalar @a }->(); +$ops{localtime} = do { my @a = localtime; scalar @a }; +$ops{gmtime} = do { my @a = gmtime; scalar @a }; sub enter { my ($self, $cv) = @_; + return 'list' if class($cv) ne 'CV'; my $op = $cv->ROOT; my $tag = tag($op); @@ -249,7 +255,11 @@ sub expect_list { my $n = name($op); my $meth = $self->can('pp_' . $n); return $self->$meth($op) if $meth; - return $ops{$n} => 0 if exists $ops{$n}; + if (exists $ops{$n}) { + my $r = $ops{$n}; + $r = { %$r } if ref $r eq 'HASH'; + return $r => 0; + } if ($op->flags & OPf_KIDS) { my @res = (0); @@ -278,7 +288,7 @@ sub expect_any { return ($self->expect_list($op))[0] => 1 if name($op) eq 'return'; - if (class($op) eq 'LOGOP') { + if (class($op) eq 'LOGOP' and not null $op->first) { my @res; my ($p, $r);