Class: Skeem::ProcedureCall

Inherits:
SkmMultiExpression show all
Defined in:
lib/skeem/s_expr_nodes.rb

Instance Attribute Summary collapse

Attributes inherited from SkmElement

#position

Instance Method Summary collapse

Methods inherited from SkmMultiExpression

#accept

Methods inherited from SkmElement

#accept, #boolean?, #bound!, #callable?, #char?, #complex?, #done!, #eqv?, #integer?, #list?, #null?, #number?, #pair?, #procedure?, #quoted!, #rational?, #real?, #skm_eq?, #skm_equal?, #string?, #symbol?, #unquoted!, #vector?, #verbatim?

Constructor Details

#initialize(aPosition, anOperator, theOperands) ⇒ ProcedureCall

Returns a new instance of ProcedureCall.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/skeem/s_expr_nodes.rb', line 55

def initialize(aPosition, anOperator, theOperands)
  super(aPosition)
  if anOperator.kind_of?(SkmVariableReference)
    # Kinky: variable names are procedure names, not variable reference
    @operator = SkmIdentifier.create(anOperator.value)
  else
    @operator = anOperator
  end
  if theOperands.nil?
    @operands = SkmEmptyList.instance
  else
    @operands = SkmPair.create_from_a(theOperands)
  end
  @operands_consumed = false
end

Instance Attribute Details

#call_siteObject

Returns the value of attribute call_site.



50
51
52
# File 'lib/skeem/s_expr_nodes.rb', line 50

def call_site
  @call_site
end

#operandsObject (readonly) Also known as: children

Returns the value of attribute operands.



48
49
50
# File 'lib/skeem/s_expr_nodes.rb', line 48

def operands
  @operands
end

#operands_consumedFalseClass, TrueClass

Returns True if all arguments are used by callee.

Returns:

  • (FalseClass, TrueClass)

    True if all arguments are used by callee.



53
54
55
# File 'lib/skeem/s_expr_nodes.rb', line 53

def operands_consumed
  @operands_consumed
end

#operatorObject (readonly)

Returns the value of attribute operator.



47
48
49
# File 'lib/skeem/s_expr_nodes.rb', line 47

def operator
  @operator
end

Instance Method Details

#associationsObject



113
114
115
# File 'lib/skeem/s_expr_nodes.rb', line 113

def associations
  %i[operator operands]
end

#evaluate(aRuntime) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/skeem/s_expr_nodes.rb', line 71

def evaluate(aRuntime)
  aRuntime.push_call(self)
  # frame_change = false
  # $stderr.puts "\n Start of ProcedureCall#evaluate #{object_id.to_s(16)}"
  # $stderr.puts "  environment: #{aRuntime.environment.object_id.to_s(16)}, "
  if aRuntime.environment&.parent
    # $stderr.puts "Parent environment #{aRuntime.environment.parent.object_id.to_s(16)}, "
    # $stderr.puts aRuntime.environment.inspect
  end
  # $stderr.puts '  operator: ' + (operands.kind_of?(SkmLambda) ? "lambda #{object_id.to_s(16)}" : operator.inspect)
  # $stderr.puts '  original operands: ' + operands.inspect
  outcome, result = determine_callee(aRuntime)
  if outcome == :callee
    actuals = transform_operands(aRuntime)
    # $stderr.puts '  transformed operands: ' + actuals.inspect
    callee = result
    # if callee.kind_of?(SkmLambda)
      # aRuntime.push(callee.environment)
      # frame_change = true
    # end
    # $stderr.puts '  callee: ' + callee.inspect
    result = callee.call(aRuntime, actuals)
    # aRuntime.pop if frame_change
  end
  aRuntime.pop_call
  # $stderr.puts "\n End of ProcedureCall#evaluate #{object_id.to_s(16)}"
  result
end

#inspectObject



107
108
109
110
111
# File 'lib/skeem/s_expr_nodes.rb', line 107

def inspect
  result = "#{inspect_prefix}#{operator.inspect}, "
  result << "@operands #{operands.inspect}#{inspect_suffix}"
  result
end

#quasiquote(aRuntime) ⇒ Object



100
101
102
103
104
105
# File 'lib/skeem/s_expr_nodes.rb', line 100

def quasiquote(aRuntime)
  quasi_operator = operator.quasiquote(aRuntime)
  quasi_operands = operands.map { |oper| oper.quasiquote(aRuntime) }

  self.class.new(position, quasi_operator, quasi_operands)
end