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.



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

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.



168
169
170
# File 'lib/bel/language.rb', line 168

def arguments
  @arguments
end

#fxObject (readonly)

Returns the value of attribute fx.



168
169
170
# File 'lib/bel/language.rb', line 168

def fx
  @fx
end

#signatureObject (readonly)

Returns the value of attribute signature.



168
169
170
# File 'lib/bel/language.rb', line 168

def signature
  @signature
end

Instance Method Details

#to_sObject



204
205
206
# File 'lib/bel/language.rb', line 204

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

#validate_signatureObject



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

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