Class: BEL::Language::Term

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/bel/language.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fx, *arguments) ⇒ Term

Returns a new instance of Term.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/bel/language.rb', line 168

def initialize(fx, *arguments)
  @fx = fx
  @arguments = arguments ||= []
  @signature = Signature.new(
    @fx.short_form,
    *@arguments.map { |arg|
      case arg
      when Term
        F.new(arg.fx.return_type)
      when Parameter
        E.new(arg.enc)
      when nil
        NullE.new
      end
    })
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



166
167
168
# File 'lib/bel/language.rb', line 166

def arguments
  @arguments
end

#fxObject (readonly)

Returns the value of attribute fx.



166
167
168
# File 'lib/bel/language.rb', line 166

def fx
  @fx
end

#signatureObject (readonly)

Returns the value of attribute signature.



166
167
168
# File 'lib/bel/language.rb', line 166

def signature
  @signature
end

Instance Method Details

#to_sObject



202
203
204
# File 'lib/bel/language.rb', line 202

def to_s
  "#{@fx.short_form}(#{@arguments.map(&:to_s).join(',')})"
end

#validate_signatureObject



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/bel/language.rb', line 185

def validate_signature
  invalids = []
  @arguments.select { |arg| Term === arg }.each do |term|
    invalids << term if not term.validate_signature
  end

  sigs = fx.signatures
  match = sigs.any? do |sig| (@signature <=> sig) >= 0 end
  invalids << self if not match
  if block_given? and not invalids.empty?
    invalids.each do |term|
      yield term, term.fx.signatures
    end
  end
  invalids.empty?
end