Class: RubyProlog::Cons
- Inherits:
-
Array
- Object
- Array
- RubyProlog::Cons
- Defined in:
- lib/ruby-prolog/ruby-prolog.rb
Overview
Lisp
Instance Method Summary collapse
-
#initialize(car, cdr) ⇒ Cons
constructor
A new instance of Cons.
- #inspect ⇒ Object
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
#inspect ⇒ Object
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 |