Class: RubyProlog::Cons

Inherits:
Array
  • Object
show all
Defined in:
lib/ruby-prolog/ruby-prolog.rb

Overview

Lisp

Instance Method Summary collapse

Constructor Details

#initialize(car, cdr) ⇒ Cons

Returns a new instance of Cons.



73
74
75
76
# File 'lib/ruby-prolog/ruby-prolog.rb', line 73

def initialize(car, cdr)
  super(2)
  self[0], self[1] = car, cdr
end

Instance Method Details

#inspectObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/ruby-prolog/ruby-prolog.rb', line 78

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