Class: BusScheme::Primitive

Inherits:
Lambda show all
Defined in:
lib/lambda.rb

Instance Attribute Summary

Attributes inherited from Lambda

#scope, #special_form

Attributes inherited from Cons

#car, #cdr

Instance Method Summary collapse

Methods inherited from Lambda

#call_as

Methods inherited from Cons

#==, #each, #empty?, #inspect, #last, #length, #map, #to_a, #to_list

Methods included from Callable

#call_as

Constructor Details

#initialize(body) ⇒ Primitive

Returns a new instance of Primitive.



47
48
49
50
# File 'lib/lambda.rb', line 47

def initialize body
  @car = @cdr = nil # avoid "Not initialized" warnings
  @body = body
end

Instance Method Details

#call(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lambda.rb', line 52

def call(*args)
  BusScheme.stack.push StackFrame.new({}, BusScheme.current_scope, @called_as)
  begin
    val = @body.call(*args)
  rescue => e
    BusScheme.stack.pop
    raise e
  end
  BusScheme.stack.pop
  return val
end