Class: Lisp::DottedPair
Overview
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, #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.
62
63
64
|
# File 'lib/mega/lisp.rb', line 62
def initialize(first = nil, second = nil)
@first, @second = first, second
end
|
Instance Attribute Details
Returns the value of attribute first.
66
67
68
|
# File 'lib/mega/lisp.rb', line 66
def first
@first
end
|
Returns the value of attribute second.
66
67
68
|
# File 'lib/mega/lisp.rb', line 66
def second
@second
end
|
Instance Method Details
#==(other) ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/mega/lisp.rb', line 107
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/mega/lisp.rb', line 76
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
|
97
98
99
|
# File 'lib/mega/lisp.rb', line 97
def inspect
'(' + repr + ')'
end
|
101
102
103
104
105
|
# File 'lib/mega/lisp.rb', line 101
def to_a
a = []
each { |e| a << e }
a
end
|
93
94
95
|
# File 'lib/mega/lisp.rb', line 93
def to_s
'(' + repr + ')'
end
|