Class: AjLisp::PrimitiveClosure
- Defined in:
- lib/ajlisp/primitive_closure.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #apply(context, args) ⇒ Object
-
#initialize(arguments, body, context = nil) ⇒ PrimitiveClosure
constructor
A new instance of PrimitiveClosure.
Methods inherited from Primitive
Constructor Details
#initialize(arguments, body, context = nil) ⇒ PrimitiveClosure
Returns a new instance of PrimitiveClosure.
9 10 11 12 13 |
# File 'lib/ajlisp/primitive_closure.rb', line 9 def initialize(arguments, body, context=nil) @arguments = arguments @body = body @context = context end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/ajlisp/primitive_closure.rb', line 5 def arguments @arguments end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/ajlisp/primitive_closure.rb', line 6 def body @body end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/ajlisp/primitive_closure.rb', line 7 def context @context end |
Instance Method Details
#apply(context, args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ajlisp/primitive_closure.rb', line 15 def apply(context, args) newcontext = context if @context then newcontext = @context end if @arguments newcontext = AjLisp::Context.new newcontext if @arguments.is_a? NamedAtom newcontext.setValue @arguments.name, AjLisp::List.make(args) else names = @arguments args.each do |arg| name = names.first.name newcontext.setValue name, arg names = names.rest end end end result = nil @body.each do |form| result = AjLisp::evaluate newcontext, form end return result end |