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)



18
19
20
21
22
# File 'lib/skeem/primitive/primitive_procedure.rb', line 18

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

#aritySkeem::Arity (readonly)

Returns number of arguments of the procedure.

Returns:

  • (Skeem::Arity)

    number of arguments of the procedure



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

def arity
  @arity
end

#codeProc (readonly)

Returns A Ruby lambda that implements the primitive procedure.

Returns:

  • (Proc)

    A Ruby lambda that implements the primitive procedure



15
16
17
# File 'lib/skeem/primitive/primitive_procedure.rb', line 15

def code
  @code
end

#identifierSkeem::SkmIdentifier (readonly)

Returns 'name' of the procedure.

Returns:



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

def identifier
  @identifier
end

Instance Method Details

#bound!(_frame) ⇒ Object

Notification that this procedure is bound to a variable

Parameters:

  • (Skemm::SkmFrame)


63
64
65
# File 'lib/skeem/primitive/primitive_procedure.rb', line 63

def bound!(_frame)
  # Do nothing
end

#call(aRuntime, theActuals) ⇒ Object

Arguments are positional in a primitive procedure.

Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/skeem/primitive/primitive_procedure.rb', line 43

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
  do_call(aRuntime, actuals)
end

#callable?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/skeem/primitive/primitive_procedure.rb', line 24

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:



37
38
39
# File 'lib/skeem/primitive/primitive_procedure.rb', line 37

def evaluate(_runtime)
  self
end

#procedure?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/skeem/primitive/primitive_procedure.rb', line 28

def procedure?
  true
end

#skm_equal?(other) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/skeem/primitive/primitive_procedure.rb', line 57

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