class Rake::LinkedList
structures in Rake.
Polylithic linked list structure used to implement several data
def self.cons(head, tail)
def self.cons(head, tail) new(head, tail) end
def self.empty
def self.empty self::EMPTY end
def self.make(*args)
Make a list out of the given arguments. This method is
def self.make(*args) result = empty args.reverse_each do |item| result = cons(item, result) end result end
def ==(other)
def ==(other) current = self while ! current.empty? && ! other.empty? return false if current.head != other.head current = current.tail other = other.tail end current.empty? && other.empty? end
def conj(item)
Polymorphically add a new element to the head of a list. The
def conj(item) self.class.cons(item, self) end
def each
def each current = self while ! current.empty? yield(current.head) current = current.tail end self end
def empty?
def empty? false end
def initialize(head, tail=EMPTY)
def initialize(head, tail=EMPTY) @head = head @tail = tail end
def inspect
def inspect items = map { |item| item.inspect }.join(", ") "LL(#{items})" end
def to_s
def to_s items = map { |item| item.to_s }.join(", ") "LL(#{items})" end