Class: Construct

Inherits:
Object show all
Defined in:
lib/forsta/construct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(car, cdr) ⇒ Construct

Returns a new instance of Construct.



4
5
6
# File 'lib/forsta/construct.rb', line 4

def initialize(car, cdr)
  @car, @cdr = car, cdr
end

Instance Attribute Details

#carObject (readonly)

Returns the value of attribute car.



2
3
4
# File 'lib/forsta/construct.rb', line 2

def car
  @car
end

#cdrObject (readonly)

Returns the value of attribute cdr.



2
3
4
# File 'lib/forsta/construct.rb', line 2

def cdr
  @cdr
end

Instance Method Details

#construct_list?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/forsta/construct.rb', line 8

def construct_list?
  cdr.construct_list?
end

#lisp_eval(environment, forms) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/forsta/construct.rb', line 16

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

#to_arrayObject



12
13
14
# File 'lib/forsta/construct.rb', line 12

def to_array
  construct_list? ? [car] + cdr.to_array : self
end