Class: Skeem::Primitive::PrimitiveProcedure
- Inherits:
-
Object
- Object
- Skeem::Primitive::PrimitiveProcedure
- Defined in:
- lib/skeem/primitive/primitive_procedure.rb
Instance Attribute Summary collapse
-
#arity ⇒ Skeem::Arity
readonly
Number of arguments of the procedure.
-
#code ⇒ Proc
readonly
A Ruby lambda that implements the primitive procedure.
-
#identifier ⇒ Skeem::SkmIdentifier
readonly
'name' of the procedure.
Instance Method Summary collapse
-
#bound!(_frame) ⇒ Object
Notification that this procedure is bound to a variable.
-
#call(aRuntime, theActuals) ⇒ Object
Arguments are positional in a primitive procedure.
- #callable? ⇒ Boolean
-
#evaluate(_runtime) ⇒ PrimitiveProcedure
This method should be invoked when the procedure isn't explicitly called (with arguments).
-
#initialize(anId, anArity, aRubyLambda) ⇒ PrimitiveProcedure
constructor
param [anArity] Arity of the lambda code (ignoring the runtime object).
- #procedure? ⇒ Boolean
- #skm_equal?(other) ⇒ Boolean
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
#arity ⇒ Skeem::Arity (readonly)
Returns number of arguments of the procedure.
12 13 14 |
# File 'lib/skeem/primitive/primitive_procedure.rb', line 12 def arity @arity end |
#code ⇒ Proc (readonly)
Returns A Ruby lambda that implements the primitive procedure.
15 16 17 |
# File 'lib/skeem/primitive/primitive_procedure.rb', line 15 def code @code end |
#identifier ⇒ Skeem::SkmIdentifier (readonly)
Returns 'name' of the procedure.
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
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.
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
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.
37 38 39 |
# File 'lib/skeem/primitive/primitive_procedure.rb', line 37 def evaluate(_runtime) self end |
#procedure? ⇒ Boolean
28 29 30 |
# File 'lib/skeem/primitive/primitive_procedure.rb', line 28 def procedure? true end |
#skm_equal?(other) ⇒ Boolean
57 58 59 |
# File 'lib/skeem/primitive/primitive_procedure.rb', line 57 def skm_equal?(other) equal?(other) end |