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.

1234567891011121314151617181920212223242526272829303132
  1. module Chervil::AST
  2. class List
  3. attr_reader :elements
  4. def initialize(elements)
  5. @elements = elements
  6. end
  7. def ==(other)
  8. @elements == other.elements
  9. end
  10. def evaluate(env)
  11. if elements.empty?
  12. []
  13. else
  14. head = @elements.first
  15. if head.class == Identifier
  16. function = env.get(head.name)
  17. if function.nil?
  18. ::Chervil::Error.new("Unbound variable #{head.name}")
  19. else
  20. function.call(@elements[1..-1].map { |arg| arg.evaluate(env) }, env)
  21. end
  22. else
  23. @elements.map { |el| el.evaluate(env) }
  24. end
  25. end
  26. end
  27. end
  28. end