Module: Alf::Algebra::Operator

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Registry

each, listen, listeners, register, registered

Methods included from TypeCheck

#joinable_headings!, #no_name_clash!, #same_heading!, #type_check_error!, #valid_ordering!

Methods included from Operand

#attr_list, coerce, #heading, #keys, #resulting_type, #to_ascii_tree, #to_relation

Instance Attribute Details

#operandsObject

Parameters:

  • operands (Array)

    Operator operands



45
46
47
# File 'lib/alf/algebra/operator.rb', line 45

def operands
  @operands
end

Class Method Details

.included(mod) ⇒ Object

Installs the class methods needed on all operators



34
35
36
37
38
39
# File 'lib/alf/algebra/operator.rb', line 34

def included(mod)
  super
  mod.extend(ClassMethods)
  mod.extend(Classification)
  register(mod, Operator)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



119
120
121
122
# File 'lib/alf/algebra/operator.rb', line 119

def ==(other)
  super || ((other.class == self.class) &&
            (other.signature.collect_on(other) == self.signature.collect_on(self)))
end

#dup(&bl) ⇒ Object



109
110
111
# File 'lib/alf/algebra/operator.rb', line 109

def dup(&bl)
  bl.nil? ? super : super.tap(&bl)
end

#hashObject



113
114
115
116
117
# File 'lib/alf/algebra/operator.rb', line 113

def hash
  @hash ||= [ self.class,
              operands,
              signature.collect_on(self) ].hash
end

#initialize(*args) ⇒ Object

Create an operator instance



48
49
50
# File 'lib/alf/algebra/operator.rb', line 48

def initialize(*args)
  signature.parse_args(args, self)
end

#signatureSignature

Returns the operator signature.

Returns:



53
54
55
# File 'lib/alf/algebra/operator.rb', line 53

def signature
  self.class.signature
end

#to_cog(plan = nil) ⇒ Object

-> to_xxx



67
68
69
# File 'lib/alf/algebra/operator.rb', line 67

def to_cog(plan = nil)
  plan ? plan.compile(self) : Alf::Compiler::Default.new.call(self)
end

#to_lispyObject



88
89
90
91
92
93
94
# File 'lib/alf/algebra/operator.rb', line 88

def to_lispy
  cmdname  = self.class.rubycase_name
  oper, args, opts = signature.collect_on(self)
  args = opts.empty? ? (oper + args) : (oper + args + [ opts ])
  args = args.map{|arg| Support.to_lispy(arg) }
  "#{cmdname}(#{args.join(', ')})"
end

#to_relvarObject



96
97
98
# File 'lib/alf/algebra/operator.rb', line 96

def to_relvar
  Relvar::Virtual.new(self)
end

#to_sObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/alf/algebra/operator.rb', line 71

def to_s
  label = ""
  label << self.class.rubycase_name.to_s
  label << "(..."
  datasets, arguments, options = signature.collect_on(self)
  arguments.each_with_index do |arg,i|
    label << ", "
    label << Alf::Support.to_lispy(arg, "[native]")
  end
  unless options.nil? or options.empty?
    label << ", "
    label << Alf::Support.to_lispy(options, "[native]")
  end
  label << ")"
  label
end

#type_check(options = {strict: false}) ⇒ Object

heading, keys, and others



59
60
61
62
63
# File 'lib/alf/algebra/operator.rb', line 59

def type_check(options = {strict: false})
  operands.each{|op| op.type_check(options) }
  _type_check(options)
  heading
end

#with_operands(*operands) ⇒ Object

identity and pseudo-mutability



102
103
104
105
106
107
# File 'lib/alf/algebra/operator.rb', line 102

def with_operands(*operands)
  dup{|copy|
    copy.operands = operands
    copy.clean_computed_attributes!
  }
end