Class: Elparser::SExpListDot

Inherits:
AbstractSExpCons show all
Defined in:
lib/elparser.rb

Overview

(list . last)

Instance Method Summary collapse

Methods inherited from AbstractSExpCons

#cons?

Methods inherited from AbstractSExp

#==, #atom?, #cons?

Constructor Details

#initialize(list, last) ⇒ SExpListDot

Returns a new instance of SExpListDot.



183
184
185
186
# File 'lib/elparser.rb', line 183

def initialize(list, last)
  @list = list
  @last = last
end

Instance Method Details

#carObject



187
188
189
# File 'lib/elparser.rb', line 187

def car
  @list[0]
end

#cdrObject



190
191
192
193
194
195
196
# File 'lib/elparser.rb', line 190

def cdr
  if @list.size == 2 then
    SExpCons.new(@list[1], @last)
  else
    SExpListDot.new(@list.slice(1..-1),@last)
  end
end

#list?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/elparser.rb', line 197

def list?
  false
end

#to_rubyObject



207
208
209
# File 'lib/elparser.rb', line 207

def to_ruby
  @list.map {|i| i.to_ruby}.push(@last.to_ruby)
end

#to_sObject



200
201
202
# File 'lib/elparser.rb', line 200

def to_s
  "("+@list.map{|i| i.to_s }.join(" ") + " . #{@last.to_s})"
end

#visit(&block) ⇒ Object



203
204
205
206
# File 'lib/elparser.rb', line 203

def visit(&block)
  @list = @list.map(&block)
  @last = block.call(@last)
end