Module: Alf::Predicate::Expr

Includes:
Factory
Included in:
Contradiction, DyadicComp, Identifier, In, Literal, NadicBool, Native, Not, QualifiedIdentifier, Tautology
Defined in:
lib/alf/predicate/nodes/expr.rb

Constant Summary collapse

OP_NEGATIONS =
{
  :eq  => :neq,
  :neq => :eq,
  :lt  => :gte,
  :lte => :gt,
  :gt  => :lte,
  :gte => :lt
}

Instance Method Summary collapse

Methods included from Factory

#_factor_predicate, #and, #between, #comp, #contradiction, #identifier, #in, #literal, #native, #not, #or, #qualified_identifier, #relation, #tautology

Instance Method Details

#!Object


23
24
25
# File 'lib/alf/predicate/nodes/expr.rb', line 23

def !
  sexpr([:not, self])
end

#&(other) ⇒ Object


27
28
29
30
31
# File 'lib/alf/predicate/nodes/expr.rb', line 27

def &(other)
  return other if other.contradiction?
  return self  if other.tautology?
  sexpr([:and, self, other])
end

#and_split(attr_list) ⇒ Object


39
40
41
# File 'lib/alf/predicate/nodes/expr.rb', line 39

def and_split(attr_list)
  (free_variables & attr_list).empty? ? [ tautology, self ] : [ self, tautology ]
end

#constant_variablesObject


51
52
53
# File 'lib/alf/predicate/nodes/expr.rb', line 51

def constant_variables
  AttrList::EMPTY
end

#contradiction?Boolean


19
20
21
# File 'lib/alf/predicate/nodes/expr.rb', line 19

def contradiction?
  false
end

#qualify(qualifier) ⇒ Object


47
48
49
# File 'lib/alf/predicate/nodes/expr.rb', line 47

def qualify(qualifier)
  Qualifier.new(qualifier).call(self)
end

#rename(renaming) ⇒ Object


43
44
45
# File 'lib/alf/predicate/nodes/expr.rb', line 43

def rename(renaming)
  Renamer.call(self, :renaming => renaming)
end

#sexpr(arg) ⇒ Object


64
65
66
# File 'lib/alf/predicate/nodes/expr.rb', line 64

def sexpr(arg)
  Factory.sexpr(arg)
end

#tautology?Boolean


15
16
17
# File 'lib/alf/predicate/nodes/expr.rb', line 15

def tautology?
  false
end

#to_proc(scope = 't') ⇒ Object


60
61
62
# File 'lib/alf/predicate/nodes/expr.rb', line 60

def to_proc(scope = 't')
  Kernel.eval(to_ruby_code(scope))
end

#to_ruby_code(scope = 't') ⇒ Object


55
56
57
58
# File 'lib/alf/predicate/nodes/expr.rb', line 55

def to_ruby_code(scope = 't')
  code = ToRubyCode.call(self, scope: scope)
  "->(t){ #{code} }"
end

#|(other) ⇒ Object


33
34
35
36
37
# File 'lib/alf/predicate/nodes/expr.rb', line 33

def |(other)
  return other if other.tautology?
  return self  if other.contradiction?
  sexpr([:or, self, other])
end