| 1 | package AI::Prolog::Term; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 13 | $REVISION = '$Id: Term.pm,v 1.10 2005/08/06 23:28:40 ovid Exp $'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | $VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Carp qw( croak confess ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Hash::Util 'lock_keys'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use aliased 'AI::Prolog::Term::Cut'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use aliased 'AI::Prolog::Parser'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use aliased 'Hash::AsObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use constant NULL => 'null'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Var is a type of term | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # A term is a basic data structure in Prolog | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # There are three types of terms: | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # 1. Values (i.e., have a functor and arguments) | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # 2. Variables (i.e., unbound) | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # 3. References (bound to another variable) | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | my $VARNUM = 1; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # controls where occurcheck is used in unification. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # In early Java versions, the occurcheck was always performed | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # which resulted in lower performance. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 13 | my $OCCURCHECK = 0; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 309 | ▶ | sub occurcheck { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
occurcheck: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 309 | my ( $class, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 309 | ▶ | $OCCURCHECK = $value if defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 309 | return $OCCURCHECK; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # controls printing of lists as [a,b] | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # instead of cons(a, cons(b, null)) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 359 | ▶ | sub prettyprint {1} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prettyprint: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | my $CUT = Cut->new(0); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 86 | ▶ | sub CUT {$CUT} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CUT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2464 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2464 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 2464 | ▶ | my $class = CORE::ref $proto || $proto; # yes, I know what I'm doing | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
CORE::ref $proto || $proto
MC/DC0%0/2
CORE::ref $proto || $proto
CORE::ref $proto
$proto
Truth table66%2/3
A || B
A= CORE::ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2464 | ▶ | return $class->_new_var unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2191 | ▶ | if ( 2 == @_ ) { # more common (performance) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1651 | ▶ | return _new_from_functor_and_arity( $class, @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | unless 'ARRAY' eq CORE::ref $_[1]; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | elsif ( 1 == @_ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 539 | my $arg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 539 | ▶ | return _new_with_id( $class, $arg ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not CORE::ref $arg and $arg =~ /^[[:digit:]]+$/
MC/DC50%1/2
not CORE::ref $arg and $arg =~ /^[[:digit:]]+$/
not CORE::ref $arg
$arg =~ /^[[:digit:]]+$/
Truth table66%2/3
not(A) and B
A= not CORE::ref $argB= $arg =~ /^[[:digit:]]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | if !CORE::ref $arg && $arg =~ /^[[:digit:]]+$/; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 41 | ▶ | return _new_from_string( $class, $arg ) if !CORE::ref $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | #return $arg->_term($class) if CORE::ref $arg && $arg->isa(Parser); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | croak("Unknown arguments to Term->new"); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 41 | ▶ | sub _new_from_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_from_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 41 | my ( $class, $string ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | my $parsed = Parser->new($string)->_term($class); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 273 | ▶ | sub _new_var { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_var: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 273 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | #print "*** _new_var @{[$VARNUM+1]}"; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 273 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 76 | functor => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | arity => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | args => [], | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # if bound is false, $self is a reference to a free variable | ||||||||||||||||||||||||||||||||||||||||||
| 81 | bound => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | varid => $VARNUM++, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # if bound and deref are both true, $self is a reference to a ref | ||||||||||||||||||||||||||||||||||||||||||
| 85 | deref => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ref => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | ID => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | varname => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | _results => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | #source => "_new_var", | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } => $class; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 273 | lock_keys %$self; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 273 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 498 | ▶ | sub _new_with_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_with_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 498 | my ( $class, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | #print "*** _new_with_id: $id"; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 498 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 103 | functor => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | arity => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | args => [], | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # if bound is false, $self is a reference to a free variable | ||||||||||||||||||||||||||||||||||||||||||
| 108 | bound => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | varid => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # if bound and deref are both true, $self is a reference to a ref | ||||||||||||||||||||||||||||||||||||||||||
| 112 | deref => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ref => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | varname => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ID => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | _results => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | #source => "_new_with_id: $id", | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } => $class; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 498 | lock_keys %$self; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 498 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1901 | ▶ | sub _new_from_functor_and_arity { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_from_functor_and_arity: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1901 | my ( $class, $functor, $arity ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 1901 | ▶ | my $print_functor = defined $functor ? $functor : 'null'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1901 | ▶ | confess "undefined arity" unless defined $arity; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | #print "*** _new_from_functor_and_arity: ($print_functor) ($arity)"; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 1901 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 132 | functor => $functor, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | arity => $arity, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | args => [], | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # if bound is false, $self is a reference to a free variable | ||||||||||||||||||||||||||||||||||||||||||
| 137 | bound => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | varid => 0, # XXX ?? | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # if bound and deref are both true, $self is a reference to a ref | ||||||||||||||||||||||||||||||||||||||||||
| 140 | deref => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ref => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | varname => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ID => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | _results => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | #source => "_new_from_functor_and_arity: ($print_functor) ($arity)", | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } => $class; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 1901 | lock_keys %$self; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 1901 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub varnum {$VARNUM} # class method | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
varnum: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 1265 | ▶ | sub functor { shift->{functor} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
functor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1511 | ▶ | sub arity { shift->{arity} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arity: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 86 | ▶ | sub args { shift->{args} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 52 | ▶ | sub varid { shift->{varid} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
varid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 262 | ▶ | sub ref { shift->{ref} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 668 | ▶ | sub predicate { sprintf "%s/%d" => $_[0]->getfunctor, $_[0]->getarity } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
predicate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 36 | ▶ | sub deref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deref: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 36 | ▶ | while ( $self->{bound} && $self->{deref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"bound"} and $self->{"deref"}
MC/DC100%2/2
$self->{"bound"} and $self->{"deref"}
$self->{"bound"}
$self->{"deref"}
Truth table100%3/3
A and B
A= $self->{"bound"}B= $self->{"deref"}
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 19 | $self = $self->{ref}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 36 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 37 | ▶ | sub bound { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bound: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 37 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 37 | ▶ | while ( $self->{bound} && $self->{deref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"bound"} and $self->{"deref"}
MC/DC0%0/2
$self->{"bound"} and $self->{"deref"}
$self->{"bound"}
$self->{"deref"}
Truth table66%2/3
A and B
A= $self->{"bound"}B= $self->{"deref"}
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self = $self->{ref}; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 37 | return $self->{bound}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 26 | ▶ | sub is_bound { shift->bound } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_bound: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub traceln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traceln: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ( $self, $msg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( $self->{trace} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | print "$msg\n"; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub dup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $self->new( $self->{functor}, $self->{arity} ); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # bind a variable to a term | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 324 | ▶ | sub bind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 324 | my ( $self, $term ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 324 | ▶ | return if $self eq $term; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 324 | ▶ | unless ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 324 | $self->{bound} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 324 | $self->{deref} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 324 | $self->{ref} = $term; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | croak( "AI::Prolog::Term->bind(" | |||||||||||||||||||||||||||||||||||||||||
| 202 | . $self->to_string | ||||||||||||||||||||||||||||||||||||||||||
| 203 | . "). Cannot bind to nonvar!" ); | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | # unbinds a term -- i.e., resets it to a variable | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 201 | ▶ | sub unbind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unbind: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 201 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 201 | $self->{bound} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 201 | $self->{ref} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | # XXX Now possible for a bind to have had no effect so ignore safety test | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # XXX if (bound) bound = false; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # XXX else IO.error("Term.unbind","Can't unbind var!"); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # set specific arguments. A primitive way of constructing terms is to | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # create them with Term(s,f) and then build up the arguments. Using the | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # parser is much simpler | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 50 | ▶ | sub setarg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setarg: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 50 | my ( $self, $pos, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 50 | ▶ | if ( $self->{bound} && !$self->{deref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"bound"} and not $self->{"deref"}
MC/DC0%0/2
$self->{"bound"} and not $self->{"deref"}
$self->{"bound"}
not $self->{"deref"}
Truth table33%1/3
A and not(B)
A= $self->{"bound"}B= not $self->{"deref"}
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 50 | $self->{args}[$pos] = $val; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | croak( "AI::Prolog::Term->setarg($pos, " | |||||||||||||||||||||||||||||||||||||||||
| 228 | . $val->to_string | ||||||||||||||||||||||||||||||||||||||||||
| 229 | . "). Cannot setarg on variables!" ); | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | # retrieves an argument of a term | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 811 | ▶ | sub getarg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getarg: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 811 | my ( $self, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | # should check if position is valid | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 811 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 811 | ▶ | return $self->{ref}->getarg($pos) if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 733 | return $self->{args}[$pos]; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | croak("AI::Prolog::Term->getarg. Error -- lookup on unbound term!"); | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 1252 | ▶ | sub getfunctor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getfunctor: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 1252 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 1252 | ▶ | return "" unless $self->{bound}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 1252 | ▶ | return $self->{ref}->getfunctor if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1160 | return $self->{functor}; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 1140 | ▶ | sub getarity { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getarity: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 1140 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 1140 | ▶ | return 0 unless $self->{bound}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 1140 | ▶ | return $self->{ref}->getarity if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 1073 | return $self->{arity}; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # check whether a variable occurs in a term | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # XXX Since a variable is not consideref to occur in itself, | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # XXX added occurs1 and a new front end called occurs() | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub occurs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
occurs: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my ( $self, $var ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | return if $self->{varid} == $var; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return $self->occurs1($var); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub occurs1 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
occurs1: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my ( $self, $var ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return $self->ref->occurs1($var) if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | for my $i ( 0 .. $self->arity - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | return 1 if $self->{args}[$i]->occurs1($var); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | return $self->varid == $var; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | # used internally for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub _dumpit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dumpit: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | local $^W; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $indent = shift || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | print( $indent . "source: ", $self->{source} ); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | print( $indent . "bound: ", ( $self->{bound} ? 'true' : 'false' ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | print( $indent . "functor: ", ( $self->{functor} || 'null' ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'functor'} || 'null'
MC/DC0%0/1
$self->{'functor'} || 'null'
$self->{'functor'}
Truth table0%0/2
A
A= $self->{'functor'}
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ( !$self->{ref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | print( $indent . "ref: null" ); | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | print( "\n$indent" . "ref:" ); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->{ref}->_dumpit( $indent . ' ' ); | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | print( $indent . "arity: ", $self->{arity} ); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ( defined $self->{args}[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | print( $indent. "args:" ); | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | foreach ( @{ $self->{args} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $_->_dumpit( $indent . " " ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | print( $indent. "args: null" ); | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | #print($indent . "args: ", scalar @{$self->{args}}) if defined $self->{args}[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | print( $indent . "deref: ", ( $self->{deref} ? 'true' : 'false' ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | print( $indent . "varid: ", $self->{varid}, "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # Unification is the basic primitive operation in logic programming. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # $stack: the stack is used to store the address of variables which | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # are bound by the unification. This is needed when backtracking. | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 476 | ▶ | sub unify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unify: called CC=15 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 476 | my ( $self, $term, $stack ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | #_dumpit($self); | ||||||||||||||||||||||||||||||||||||||||||
| 322 | #_dumpit($term); | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 476 | foreach ( $self, $term ) { | |||||||||||||||||||||||||||||||||||||||||
| 325 | 952 | ▶ | $_ = $_->{ref} while $_->{bound} and $_->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_->{"bound"} and $_->{"deref"}
MC/DC100%2/2
$_->{"bound"} and $_->{"deref"}
$_->{"bound"}
$_->{"deref"}
Truth table100%3/3
A and B
A= $_->{"bound"}B= $_->{"deref"}
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 476 | ▶ | if ( $self->{bound} and $term->{bound} ) { # bound and not deref | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"bound"} and $term->{"bound"}
MC/DC100%2/2
$self->{"bound"} and $term->{"bound"}
$self->{"bound"}
$term->{"bound"}
Truth table100%3/3
A and B
A= $self->{"bound"}B= $term->{"bound"}
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 176 | ▶ | if ( $self->functor eq $term->getfunctor | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->functor eq $term->getfunctor and $self->arity == $term->getarity
MC/DC50%1/2
$self->functor eq $term->getfunctor and $self->arity == $term->getarity
$self->functor eq $term->getfunctor
$self->arity == $term->getarity
Truth table66%2/3
A and B
A= $self->functor eq $term->getfunctorB= $self->arity == $term->getarity
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | && $self->arity == $term->getarity ) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 164 | for my $i ( 0 .. $self->arity - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 333 | return | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 350 | ▶ | unless $self->{args}[$i] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | ->unify( $term->getarg($i), $stack ); | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 147 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 12 | return; # functor/arity don't match ... | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } # at least one arg not bound ... | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 300 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | # added missing occurcheck | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 58 | ▶ | if ( $self->occurcheck ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ( $self->occurs( $term->varid ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 58 | $term->bind($self); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 58 | push @{$stack} => $term; # side-effect -- setting stack vars | |||||||||||||||||||||||||||||||||||||||||
| 353 | 58 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | # do occurcheck if turned on | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 242 | ▶ | return if $self->occurcheck && $term->occurs( $self->varid ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->occurcheck and $term->occurs($self->varid)
MC/DC0%0/2
$self->occurcheck and $term->occurs($self->varid)
$self->occurcheck
$term->occurs($self->varid)
Truth table33%1/3
A and B
A= $self->occurcheckB= $term->occurs($self->varid)
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 242 | $self->bind($term); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 242 | push @{$stack} => $self; # save for backtracking | |||||||||||||||||||||||||||||||||||||||||
| 360 | 242 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | # refresh creates new variables. If the variables already exist | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # in its arguments then they are used. This is used when parsing | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # a clause so that variables throughout the clause are shared. | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # Includes a copy operation. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 1183 | ▶ | sub refresh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 1183 | my ( $self, $term_aref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 1183 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 745 | ▶ | if ( $self->{deref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 437 | return $self->{ref}->refresh($term_aref); | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 308 | ▶ | if ( 0 == $self->{arity} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 58 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | my $term = ( CORE::ref $self) | ||||||||||||||||||||||||||||||||||||||||||
| 380 | ->_new_from_functor_and_arity( $self->{functor}, | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 250 | $self->{arity} ); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 250 | for my $i ( 0 .. $self->{arity} - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 383 | $term->{args}[$i] | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 562 | = $self->{args}[$i]->refresh($term_aref); | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 250 | return $term; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | # else unbound | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 438 | ▶ | unless ( $term_aref->[ $self->{varid} ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 272 | $term_aref->[ $self->{varid} ] = $self->new; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 438 | return $term_aref->[ $self->{varid} ]; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 15 | ▶ | sub to_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 15 | $self->{_results} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | # @results is the full results, if we ever need it | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 15 | my @results = $self->_to_data($self); | |||||||||||||||||||||||||||||||||||||||||
| 404 | 15 | return AsObject->new( $self->{_results} ), \@results; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 353 | ▶ | sub _to_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_data: called CC=16 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 353 | my ( $self, $parent ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 353 | ▶ | if ( defined $self->{varname} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # XXX here's where the [HEAD|TAIL] bug is. The engine works fine, | ||||||||||||||||||||||||||||||||||||||||||
| 412 | # but we can't bind TAIL to a result object and are forced to | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # switch to raw_results. | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 26 | my $varname = delete $self->{varname}; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 26 | ( $parent->{_results}{$varname} ) = $self->_to_data($parent); | |||||||||||||||||||||||||||||||||||||||||
| 416 | 26 | $self->{varname} = $varname; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 353 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 349 | my $functor = $self->functor; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 349 | my $arity = $self->arity; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 349 | ▶ | return $self->ref->_to_data($parent) if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 209 | ▶ | return [] if NULL eq $functor && !$arity; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"null" eq $functor and not $arity
MC/DC50%1/2
"null" eq $functor and not $arity
"null" eq $functor
not $arity
Truth table66%2/3
A and not(B)
A= "null" eq $functorB= not $arity
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 201 | ▶ | if ( "cons" eq $functor && 2 == $arity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"cons" eq $functor and 2 == $arity
MC/DC50%1/2
"cons" eq $functor and 2 == $arity
"cons" eq $functor
2 == $arity
Truth table66%2/3
A and B
A= "cons" eq $functorB= 2 == $arity
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 46 | my @result = $self->{args}[0]->_to_data($parent); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 46 | my $term = $self->{args}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 46 | ▶ | while ( "cons" eq $term->getfunctor && 2 == $term->getarity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"cons" eq $term->getfunctor and 2 == $term->getarity
MC/DC50%1/2
"cons" eq $term->getfunctor and 2 == $term->getarity
"cons" eq $term->getfunctor
2 == $term->getarity
Truth table66%2/3
A and B
A= "cons" eq $term->getfunctorB= 2 == $term->getarity
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 86 | ▶ | if ( $term->{varname} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | push @result => $term->_to_data($parent); | |||||||||||||||||||||||||||||||||||||||||
| 430 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 85 | push @result => $term->getarg(0)->_to_data($parent); | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 86 | $term = $term->getarg(1); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | # XXX Not really sure about this one | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 46 | ▶ | push @result => $term->_to_data($parent) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
"null" eq $term->getfunctor and not $term->getarity
MC/DC0%0/2
"null" eq $term->getfunctor and not $term->getarity
"null" eq $term->getfunctor
not $term->getarity
Truth table33%1/3
A and not(B)
A= "null" eq $term->getfunctorB= not $term->getarity
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | unless NULL eq $term->getfunctor && !$term->getarity; | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | # ? "]" | ||||||||||||||||||||||||||||||||||||||||||
| 441 | # : "|" . $term->_to_data($parent) . "]"; | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 46 | return \@result; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 155 | my @results = $self->functor; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 155 | ▶ | if ( $self->arity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | #push @results => []; | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 15 | my $arity = $self->arity; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 15 | my @args = @{ $self->args }; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 15 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 15 | for my $i ( 0 .. $arity - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 453 | 40 | push @results => $args[$i]->_to_data($parent); | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | # I have no idea what the following line was doing. | ||||||||||||||||||||||||||||||||||||||||||
| 457 | #push @results => $args[$arity - 1]->_to_data($parent) | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 155 | return @results; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | } # else unbound; | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 13 | my %varname_for; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 13 | my $varname = 'A'; | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 51 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 51 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 51 | return $self->_to_string(@_); | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 380 | ▶ | sub _to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_string: called CC=19 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 380 | my ( $self, $extended ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 380 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | 359 | my $functor = $self->functor; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 359 | my $arity = $self->arity; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 359 | my $prettyprint = $self->prettyprint; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 359 | ▶ | return $self->ref->_to_string($extended) if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 246 | ▶ | return "[]" if NULL eq $functor && !$arity && $prettyprint; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
"null" eq $functor and not $arity and $prettyprint
"null" eq $functor and not $arity
MC/DC33%1/3
"null" eq $functor and not $arity and $prettyprint
"null" eq $functor
not $arity
$prettyprint
Truth table50%2/4
A and not(B) and C
A= "null" eq $functorB= not $arityC= $prettyprint
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 242 | my $string; | |||||||||||||||||||||||||||||||||||||||||
| 484 | 242 | ▶ | if ( "cons" eq $functor && 2 == $arity && $prettyprint ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
"cons" eq $functor and 2 == $arity and $prettyprint
"cons" eq $functor and 2 == $arity
MC/DC33%1/3
"cons" eq $functor and 2 == $arity and $prettyprint
"cons" eq $functor
2 == $arity
$prettyprint
Truth table50%2/4
A and B and C
A= "cons" eq $functorB= 2 == $arityC= $prettyprint
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 29 | $string = "[" . $self->{args}[0]->_to_string; | |||||||||||||||||||||||||||||||||||||||||
| 486 | 29 | my $term = $self->{args}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 29 | ▶ | while ( "cons" eq $term->getfunctor && 2 == $term->getarity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"cons" eq $term->getfunctor and 2 == $term->getarity
MC/DC50%1/2
"cons" eq $term->getfunctor and 2 == $term->getarity
"cons" eq $term->getfunctor
2 == $term->getarity
Truth table66%2/3
A and B
A= "cons" eq $term->getfunctorB= 2 == $term->getarity
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 59 | $string .= "," . $term->getarg(0)->_to_string; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 59 | $term = $term->getarg(1); | |||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | $string .= | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 29 | ▶ | ( NULL eq $term->getfunctor && !$term->getarity ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
"null" eq $term->getfunctor and not $term->getarity
MC/DC0%0/2
"null" eq $term->getfunctor and not $term->getarity
"null" eq $term->getfunctor
not $term->getarity
Truth table33%1/3
A and not(B)
A= "null" eq $term->getfunctorB= not $term->getarity
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | ? "]" | ||||||||||||||||||||||||||||||||||||||||||
| 496 | : "|" . $term->_to_string . "]"; | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 29 | return "$string"; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 213 | $string = $self->functor; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 213 | ▶ | if ( $self->arity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 61 | $string .= "("; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 61 | ▶ | if ( $self->arity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 61 | local $Data::Dumper::Terse = 1; # don't use $var1 | |||||||||||||||||||||||||||||||||||||||||
| 505 | 61 | local $Data::Dumper::Indent = 0; # no newline | |||||||||||||||||||||||||||||||||||||||||
| 506 | my @args = map { | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 128 | my $string = $_->_to_string; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 128 | ▶ | $string =~ /\s/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string =~ /\s/ and not $_->arity
MC/DC100%2/2
$string =~ /\s/ and not $_->arity
$string =~ /\s/
not $_->arity
Truth table100%3/3
A and not(B)
A= $string =~ /\s/B= not $_->arity
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | && !$_->arity | ||||||||||||||||||||||||||||||||||||||||||
| 510 | ? Data::Dumper::Dumper($string) | ||||||||||||||||||||||||||||||||||||||||||
| 511 | : $string; | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 61 | } @{ $self->args }; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 61 | $string .= join ", " => @args; | |||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 61 | $string .= ")"; | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 213 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } # else unbound; | ||||||||||||||||||||||||||||||||||||||||||
| 520 | # return "_" . $self->varid; | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 21 | ▶ | my $var = $self->{varname} || $varname_for{ $self->varid } || $varname++; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{'varname'} || $varname_for{$self->varid} || $varname++
$self->{"varname"} or $varname_for{$self->varid}
MC/DC0%0/3
$self->{'varname'} || $varname_for{$self->varid} || $varname++
$self->{"varname"}
$varname_for{$self->varid}
$varname++
Truth table50%2/4
A or B || C
A= $self->{"varname"}B= $varname_for{$self->varid}C= $varname++
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 21 | $varname_for{ $self->varid } = $var; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 21 | return $var; | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | # ---------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 527 | # Copy a term to put in the database | ||||||||||||||||||||||||||||||||||||||||||
| 528 | # - with new variables (freshly renumbered) | ||||||||||||||||||||||||||||||||||||||||||
| 529 | # ---------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | # XXX XProlog | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 13 | my %CVDICT; | |||||||||||||||||||||||||||||||||||||||||
| 533 | my $CVN; | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | sub clean_up { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_up: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | %CVDICT = (); | |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $CVN = 0; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | return $self->_clean_up; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | sub _clean_up { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clean_up: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my $term; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ( $self->{deref} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | return $self->{ref}->_clean_up; | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | ▶ | elsif ( defined $self->{arity} && 0 == $self->{arity} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $self->{"arity"} and 0 == $self->{"arity"}
MC/DC0%0/2
defined $self->{"arity"} and 0 == $self->{"arity"}
defined $self->{"arity"}
0 == $self->{"arity"}
Truth table0%0/3
A and B
A= defined $self->{"arity"}B= 0 == $self->{"arity"}
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $term = $self->dup; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | for my $i ( 0 .. $self->{arity} - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $term->{args}[$i] = $self->{args}[$i]->_clean_up; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | else { # unbound | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | $term = $CVDICT{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | unless ($term) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $term = $self->new( $CVN++ ); | |||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $CVDICT{$self} = $term; # XXX Should this be $self->to_string? | |||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | return $term; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | # From XProlog | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 46 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=12 SCAR=25.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | # int i, res = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 46 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 46 | my ( $i, $res ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 46 | ▶ | unless ( $self->{bound} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | my $term = $self->to_string; | |||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | croak("Tried to to get value of unbound term ($term)"); | |||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 45 | ▶ | return $self->{ref}->value if $self->{deref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 21 | my $functor = $self->getfunctor; | |||||||||||||||||||||||||||||||||||||||||
| 582 | 21 | my $arity = $self->getarity; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 21 | ▶ | if ( 'rnd' eq $functor && 1 == $arity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
"rnd" eq $functor and 1 == $arity
MC/DC0%0/2
"rnd" eq $functor and 1 == $arity
"rnd" eq $functor
1 == $arity
Truth table33%1/3
A and B
A= "rnd" eq $functorB= 1 == $arity
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | # implement rand | ||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 21 | ▶ | if ( $arity < 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $term = $self->to_string; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | croak("Term ($term) is not binary"); | |||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 21 | my $arg0 = $self->{args}[0]->value; | |||||||||||||||||||||||||||||||||||||||||
| 592 | 21 | my $arg1 = $self->{args}[1]->value; | |||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 21 | ▶ | return $arg0 + $arg1 if 'plus' eq $functor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | 17 | ▶ | return $arg0 - $arg1 if 'minus' eq $functor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 11 | ▶ | return $arg0 * $arg1 if 'mult' eq $functor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 5 | ▶ | return $arg0 / $arg1 if 'div' eq $functor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | ▶ | return $arg0 % $arg1 if 'mod' eq $functor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 3 | ▶ | return $arg0**$arg1 if 'pow' eq $functor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | croak("Unknown operator ($functor)"); | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | __END__ | ||||||||||||||||||||||||||||||||||||||||||