Class: Skeem::Primitive::PrimitiveProcedure

Inherits:
Object
  • Object
show all
Defined in:
lib/skeem/primitive/primitive_procedure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(anId, anArity, aRubyLambda) ⇒ PrimitiveProcedure

param [anArity] Arity of the lambda code (ignoring the runtime object)



11
12
13
14
15
# File 'lib/skeem/primitive/primitive_procedure.rb', line 11

def initialize(anId, anArity, aRubyLambda)
  @identifier = anId.kind_of?(String) ? SkmIdentifier.create(anId) : anId
  @code = code_validated(aRubyLambda)
  @arity = arity_validated(anArity)
end

Instance Attribute Details

#arityObject (readonly)

Returns the value of attribute arity.



7
8
9
# File 'lib/skeem/primitive/primitive_procedure.rb', line 7

def arity
  @arity
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/skeem/primitive/primitive_procedure.rb', line 8

def code
  @code
end

#identifierObject (readonly)

Returns the value of attribute identifier.



6
7
8
# File 'lib/skeem/primitive/primitive_procedure.rb', line 6

def identifier
  @identifier
end

Instance Method Details

#bound!(_frame) ⇒ Object

Notification that this procedure is bound to a variable

Parameters:

  • (Skemm::SkmFrame)


55
56
57
# File 'lib/skeem/primitive/primitive_procedure.rb', line 55

def bound!(_frame)
  # Do nothing
end

#call(aRuntime, theActuals) ⇒ Object

Arguments are positional in a primitive procedure.

Parameters:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/skeem/primitive/primitive_procedure.rb', line 36

def call(aRuntime, theActuals)
  actuals = theActuals
  # $stderr.puts "--- Start of procedure #{identifier}"
  # actuals.each { |actual| $stderr.puts '  Actual: ' + actual.inspect }
  check_actual_count(actuals)
  # TODO: check that next line became useless
  # aProcedureCall.operands_consumed = true
  result = do_call(aRuntime, actuals)
  # $stderr.puts "  Result: #{result.inspect}"
  # $stderr.puts "--- End of procedure #{identifier}"
  result
end

#callable?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/skeem/primitive/primitive_procedure.rb', line 17

def callable?
  true
end

#evaluate(_runtime) ⇒ PrimitiveProcedure

This method should be invoked when the procedure isn't explicitly called (with arguments). In this case, the name of procedure just returns the procedure object itself.

Parameters:

Returns:



30
31
32
# File 'lib/skeem/primitive/primitive_procedure.rb', line 30

def evaluate(_runtime)
  self
end

#procedure?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/skeem/primitive/primitive_procedure.rb', line 21

def procedure?
  true
end

#skm_equal?(other) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/skeem/primitive/primitive_procedure.rb', line 49

def skm_equal?(other)
  equal?(other)
end