Class: Trxl::Function::Closure
- Inherits:
-
Object
- Object
- Trxl::Function::Closure
- Defined in:
- lib/trxl/trxl.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
Instance Method Summary collapse
- #apply(args) ⇒ Object
-
#initialize(function, env = Environment.new) ⇒ Closure
constructor
A new instance of Closure.
- #to_s(other_env = Environment.new) ⇒ Object
Constructor Details
#initialize(function, env = Environment.new) ⇒ Closure
Returns a new instance of Closure.
135 136 137 138 |
# File 'lib/trxl/trxl.rb', line 135 def initialize(function, env = Environment.new) @function = function @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
133 134 135 |
# File 'lib/trxl/trxl.rb', line 133 def env @env end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
133 134 135 |
# File 'lib/trxl/trxl.rb', line 133 def function @function end |
Instance Method Details
#apply(args) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/trxl/trxl.rb', line 140 def apply(args) env.enter_scope return_value = function.body.eval(function.formal_parameter_list.bind(args, env)) env.exit_scope return_value end |
#to_s(other_env = Environment.new) ⇒ Object
147 148 149 |
# File 'lib/trxl/trxl.rb', line 147 def to_s(other_env = Environment.new) function.text_value #"fun#{function.formal_parameter_list.to_s(env)} {#{function.body.to_s(other_env.merge(env.local))}}" end |