Class: Plasma::Interpreter::ApplyNode

Inherits:
ColNode show all
Defined in:
lib/plasma/interpreter/plasma_grammarnode.rb

Instance Method Summary collapse

Methods inherited from ColNode

#col

Methods inherited from PlasmaNode

#empty?

Instance Method Details

#evaluate(env) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/plasma/interpreter/plasma_grammarnode.rb', line 286

def evaluate(env)
  args = col.map{|arg| arg.evaluate(env)}

  begin
    closure = applied.evaluate(env)
    return closure.apply(*args)
  rescue UnresolvedSymbolException => detail
    begin
      return args.first.send(detail.symbol, *args.slice(1..args.length))
    rescue ArgumentError => arg
      begin
        slice = args.slice(1...args.length-1)
        proc = args.last.to_proc

        return args.first.send(detail.symbol, *slice, &proc)
      rescue Exception => brg
        raise TooManyArgumentsException.new(self.text_value), "too many arguments in #{self.text_value}", caller
      end
    end
  end
end