class Apricot::List

A linked list implementation representing (a b c) syntax in Apricot

Constants

EMPTY_LIST

Attributes

count[R]
head[R]
tail[R]

Public Class Methods

[](*args) click to toggle source
# File lib/apricot/list.rb, line 6
def self.[](*args)
  list = EMPTY_LIST
  args.reverse_each do |arg|
    list = list.cons(arg)
  end
  list
end
new(head, tail) click to toggle source
# File lib/apricot/list.rb, line 16
def initialize(head, tail)
  @head = head
  @tail = tail || EMPTY_LIST
  @count = tail ? tail.count + 1 : 1
end

Public Instance Methods

cons(x) click to toggle source
# File lib/apricot/list.rb, line 22
def cons(x)
  List.new(x, self)
end
first() click to toggle source
# File lib/apricot/list.rb, line 37
def first
  @head
end
inspect() click to toggle source
# File lib/apricot/list.rb, line 49
def inspect
  return '()' if empty?

  str = '('
  each {|x| str << x.apricot_inspect << ' ' }
  str.chop!
  str << ')'
end
Also aliased as: to_s
next() click to toggle source
# File lib/apricot/list.rb, line 41
def next
  @tail.empty? ? nil : @tail
end
to_list() click to toggle source
# File lib/apricot/list.rb, line 33
def to_list
  self
end
to_s()
Alias for: inspect
to_seq() click to toggle source
# File lib/apricot/list.rb, line 45
def to_seq
  self
end

Private Instance Methods

initialize_copy(other) click to toggle source
Calls superclass method
# File lib/apricot/list.rb, line 26
def initialize_copy(other)
  super
  @tail = other.tail.dup if other.tail && !other.tail.empty?
end