Chervil is a toy Lisp interpreter written in Ruby
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

application.rb 582B

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) }, env)
  19. end
  20. end
  21. end
  22. end
  23. end