class Construct attr_reader :car, :cdr def initialize(car, cdr) @car, @cdr = car, cdr end def construct_list? cdr.construct_list? end def to_array construct_list? ? [car] + cdr.to_array : self end def lisp_eval(environment, forms) if forms.defined?(car) # TODO implement and test else car.lisp_eval(environment, forms). call(*cdr.to_array.map { |x| x.lisp_eval(environment, forms) }) end end end