Class: Locomotive::RelationalAlgebra::RelLambda
- Inherits:
-
Binary
- Object
- RelAlgAstNode
- Operator
- Binary
- Locomotive::RelationalAlgebra::RelLambda
- Defined in:
- lib/locomotive/relational_algebra/operators/abstraction/lambda.rb
Instance Attribute Summary
Attributes inherited from Operator
Attributes included from AstHelpers::AstNode
#kind, #left_child, #owner, #right_child, #value
Instance Method Summary collapse
-
#apply(arg) ⇒ Object
performs a beta reduction on the right plan side.
- #bound ⇒ Object
- #clone ⇒ Object
- #free ⇒ Object
-
#initialize(op1, op2) ⇒ RelLambda
constructor
A new instance of RelLambda.
- #left_and_right(op1, op2) ⇒ Object
- #serialize ⇒ Object
- #set(var, plan) ⇒ Object
Methods inherited from Operator
#to_xml, #xml_content, #xml_kind, #xml_schema
Methods included from XML
Methods included from AstHelpers::Annotations
Methods included from AstHelpers::AstNode
#has_left_child?, #has_right_child?, #is_leaf?, #traverse, #traverse_strategy=
Constructor Details
#initialize(op1, op2) ⇒ RelLambda
Returns a new instance of RelLambda.
7 8 9 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 7 def initialize(op1, op2) super(op1,op2) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Locomotive::AstHelpers::Annotations
Instance Method Details
#apply(arg) ⇒ Object
performs a beta reduction on the right plan side
40 41 42 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 40 def apply(arg) right.set(left, arg) end |
#bound ⇒ Object
74 75 76 77 78 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 74 def bound # the variable in the right branch # is now a bound variable [left.clone] + right.bound end |
#clone ⇒ Object
44 45 46 47 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 44 def clone RelLambda.new(op1.clone, op2.clone) end |
#free ⇒ Object
68 69 70 71 72 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 68 def free # the variable in the left branch # is not a free variable anymore right.free - [left] end |
#left_and_right(op1, op2) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 11 def left_and_right(op1,op2) self.schema = Schema.new( { Iter.new(1) => [RNat.type], Pos.new(1) => [RNat.type], # this is a dummy node Item.new(1) => [RNat.type] } ) super(op1,op2) end |
#serialize ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 20 def serialize xml_id = 0 self.traverse do |op| op.ann_xml_id = xml_id += 1 end xml_list = [] self.traverse_strategy = Locomotive::AstHelpers::PostOrderTraverse self.traverse do |op| xml_list << op.to_xml end parametrized_plan :comment => "not mentioned for execution" do xml_list.join end end |
#set(var, plan) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/locomotive/relational_algebra/operators/abstraction/lambda.rb', line 49 def set(var,plan) if var == self.left right.clone else if !right.free.member?(var) or !plan.free.member?(left) RelLambda.new( left.clone, right.set(var, plan)) else # alpha reduction new_var = Variable.new_variable RelLambda.new( new_var, right.set(left,new_var)).set(var,plan) end end end |