Chervil is a toy Lisp interpreter written in Ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application.rb 577B

123456789101112131415161718192021222324252627
  1. module Chervil::AST
  2. class Application
  3. attr_reader :expr
  4. attr_reader :arguments
  5. def initialize(expr, arguments)
  6. @expr = expr
  7. @arguments = arguments
  8. end
  9. def ==(other)
  10. @expr == other.expr && @arguments == other.arguments
  11. end
  12. def evaluate(env)
  13. if @expr.class == Identifier
  14. function = env.get(@expr.name)
  15. if function.nil?
  16. ::Chervil::Error.new("Unbound variable #{@expr.name}")
  17. else
  18. function.call(@arguments.map { |arg| arg.evaluate(env) })
  19. end
  20. end
  21. end
  22. end
  23. end