class RubyProlog::Cons

Lisp

Public Class Methods

new(car, cdr) click to toggle source
Calls superclass method
# File lib/ruby-prolog/ruby-prolog.rb, line 152
def initialize(car, cdr)
  super(2)
  self[0], self[1] = car, cdr
end

Public Instance Methods

inspect() click to toggle source
# File lib/ruby-prolog/ruby-prolog.rb, line 157
def inspect
  repr = proc {|x|
    car, cdr = x[0], x[1]
    if cdr.nil? then [car.inspect]
    elsif Cons === cdr then repr[cdr].unshift(car.inspect)
    else [car.inspect, '.', cdr.inspect]
    end
  }
  return '(' + repr[self].join(' ') + ')'
end
to_prolog() click to toggle source
# File lib/ruby-prolog/ruby-prolog.rb, line 168
def to_prolog
  current = self
  array = []
  while current
    array << case current[0]
      when :CUT then '!'
      when :_ then '_'
      else current[0].to_prolog
      end
    current = current[1]
  end
  return array.join(', ')
end