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
- #to_prolog ⇒ Object
Constructor Details
#initialize(car, cdr) ⇒ Cons
Returns a new instance of Cons.
144 145 146 147 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 144 def initialize(car, cdr) super(2) self[0], self[1] = car, cdr end |
Instance Method Details
#inspect ⇒ Object
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 149 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 ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 160 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 |