Class: Lisp::DottedPair
Overview
Constant Summary
Constants included
from Lisp
VERSION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Lisp
#accumulate, #all?, #append, #assoc, #atom?, #car, #cdr, #cons, #consonto, #drop, #equal?, #exists?, #explode, #filter, format, #implode, #length, #link, #list, #map, #member?, #null?, #pair!, #pair?, #pairlis, #prod, #reduce, #reverse, #set, #set_car!, #set_cdr!, #sum, #take, #zip
Constructor Details
#initialize(first = nil, second = nil) ⇒ DottedPair
Returns a new instance of DottedPair.
55
56
57
|
# File 'lib/carat/lisp.rb', line 55
def initialize(first = nil, second = nil)
@first, @second = first, second
end
|
Instance Attribute Details
Returns the value of attribute first.
59
60
61
|
# File 'lib/carat/lisp.rb', line 59
def first
@first
end
|
Returns the value of attribute second.
59
60
61
|
# File 'lib/carat/lisp.rb', line 59
def second
@second
end
|
Instance Method Details
#==(other) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/carat/lisp.rb', line 100
def ==(other)
if pair?(self) and pair?(other)
car(self) == car(other) and cdr(self) == cdr(other)
else
if pair?(self) then false else self == other end
end
end
|
#each(&block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/carat/lisp.rb', line 69
def each(&block)
if @first
if @first.is_a? DottedPair
@first.each(&block)
else
block.call(@first)
end
end
if @second
if @second.is_a? DottedPair
@second.each(&block)
else
block.call(@second)
end
end
end
|
90
91
92
|
# File 'lib/carat/lisp.rb', line 90
def inspect
'(' + repr + ')'
end
|
94
95
96
97
98
|
# File 'lib/carat/lisp.rb', line 94
def to_a
a = []
each { |e| a << e }
a
end
|
86
87
88
|
# File 'lib/carat/lisp.rb', line 86
def to_s
'(' + repr + ')'
end
|