requires:
B: 0
Carp: 0
- List::Util: 0
XSLoader: 0
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html
ABSTRACT_FROM => 'lib/Sub/Nary.pm',
PL_FILES => {},
PREREQ_PM => {
- 'B' => 0,
- 'Carp' => 0,
- 'List::Util' => 0,
- 'XSLoader' => 0
+ 'B' => 0,
+ 'Carp' => 0,
+ 'XSLoader' => 0
},
dist => {
PREOP => 'pod2text lib/Sub/Nary.pm > $(DISTVNAME)/README; '
ST(0) = sv_2mortal(newRV_noinc((SV *) res));
XSRETURN(1);
+void
+add(...)
+PROTOTYPE: @
+PREINIT:
+ HV *res;
+ SV *cur, *val;
+ HE *key, *old;
+ I32 i;
+CODE:
+ if (!items)
+ XSRETURN_UNDEF;
+ res = newHV();
+ for (i = 0; i < items; ++i) {
+ cur = ST(i);
+ if (!SvOK(cur))
+ continue;
+ if (!SvROK(cur)) {
+ if (strEQ(SvPV_nolen(cur), "list")) {
+ hv_clear(res);
+ val = newSVuv(1);
+ if (!hv_store(res, "list", 4, val, sn_hash_list))
+ SvREFCNT_dec(val);
+ break;
+ } else {
+ NV v = 1;
+ if ((old = hv_fetch_ent(res, cur, 1, 0)) && SvOK(val = HeVAL(old)))
+ v += SvNV(val);
+ val = newSVnv(v);
+ if (!hv_store_ent(res, cur, val, 0))
+ SvREFCNT_dec(val);
+ continue;
+ }
+ }
+ cur = SvRV(cur);
+ hv_iterinit((HV *) cur);
+ while (key = hv_iternext((HV *) cur)) {
+ SV *k = HeSVKEY_force(key);
+ NV v = SvNV(HeVAL(key));
+ if ((old = hv_fetch_ent(res, k, 1, 0)) && SvOK(val = HeVAL(old)))
+ v += SvNV(val);
+ val = newSVnv(v);
+ if (!hv_store_ent(res, k, val, 0))
+ SvREFCNT_dec(val);
+ }
+ }
+ if (!hv_iterinit(res)) {
+ SvREFCNT_dec(res);
+ XSRETURN_UNDEF;
+ }
+ ST(0) = sv_2mortal(newRV_noinc((SV *) res));
+ XSRETURN(1);
+
void
combine(...)
PROTOTYPE: @
PROBABILITY OF RETURN
The probability is computed as such :
- * All the returning points in the same subroutine (i.e. all the explicit
- "return" and the last computed value) are considered equally possible.
+ * When branching, each branch is considered equally possible.
For example, the subroutine
sub simple {
}
}
- it is considered to return 1 (when the two tests fail, the last
- computed value is returned, which here is "$x > 0.9" evaluated in
- the scalar context of the test), 2 or 3 arguments each with
- probability "1/3".
+ it is considered to return 3 scalars with probability "1/2", 2 with
+ probability "1/2 * 1/2 = 1/4" and 1 (when the two tests fail, the
+ last computed value is returned, which here is "$x > 0.9" evaluated
+ in the scalar context of the test) with remaining probability "1/4".
* The total probability law for a given returning point is the
convolution product of the probabilities of its list elements.
DEPENDENCIES
perl 5.8.1.
- Carp (standard since perl 5), B (since perl 5.005), XSLoader (since perl
- 5.006) and List::Util (since perl 5.007003).
+ Carp (standard since perl 5), B (since perl 5.005) and XSLoader (since
+ perl 5.006).
AUTHOR
Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
use warnings;
use Carp qw/croak/;
-use List::Util qw/reduce/;
use B qw/class ppname svref_2object OPf_KIDS/;
return $r;
}
-sub add {
- reduce {
- $a->{$_} += $b->{$_} for keys %$b;
- $a
- } map { (ref) ? $_ : { $_ => 1 } } grep defined, @_;
-}
-
my %ops;
$ops{$_} = 1 for scalops;
L<perl> 5.8.1.
-L<Carp> (standard since perl 5), L<B> (since perl 5.005), L<XSLoader> (since perl 5.006) and L<List::Util> (since perl 5.007003).
+L<Carp> (standard since perl 5), L<B> (since perl 5.005) and L<XSLoader> (since perl 5.006).
=head1 AUTHOR