Class: Nendo::Cell
- Inherits:
-
Object
- Object
- Nendo::Cell
- Includes:
- Enumerable
- Defined in:
- lib/nendo/ruby/types.rb
Instance Attribute Summary collapse
-
#car ⇒ Object
Returns the value of attribute car.
-
#cdr ⇒ Object
Returns the value of attribute cdr.
Instance Method Summary collapse
-
#each ⇒ Object
Supporting iterator.
- #first ⇒ Object
- #getLastAtom ⇒ Object
-
#initialize(car = Nil.new, cdr = Nil.new) ⇒ Cell
constructor
A new instance of Cell.
- #isDotted ⇒ Object
- #isNull ⇒ Object
- #lastAtom ⇒ Object
- #lastCell ⇒ Object
- #length ⇒ Object
- #second ⇒ Object (also: #cdar)
-
#size ⇒ Object
alias of length.
- #third ⇒ Object (also: #cddar)
- #to_arr ⇒ Object
Constructor Details
Instance Attribute Details
#car ⇒ Object
Returns the value of attribute car.
88 89 90 |
# File 'lib/nendo/ruby/types.rb', line 88 def car @car end |
#cdr ⇒ Object
Returns the value of attribute cdr.
88 89 90 |
# File 'lib/nendo/ruby/types.rb', line 88 def cdr @cdr end |
Instance Method Details
#each ⇒ Object
Supporting iterator
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/nendo/ruby/types.rb', line 90 def each # Supporting iterator h = {} if not isNull it = self while Nil != it.class h[ it.hash ] = true # printf( "%s : %s\n", it.car, it.hash ) yield it if it.cdr.is_a? Cell it = it.cdr if h.has_key?( it.hash ) # found circular-list. it = Nil.new end else it = Nil.new end end end end |
#first ⇒ Object
149 150 151 |
# File 'lib/nendo/ruby/types.rb', line 149 def first self.car end |
#getLastAtom ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/nendo/ruby/types.rb', line 133 def getLastAtom if self.lastAtom self.lastCell.cdr else Nendo::Nil.new end end |
#isDotted ⇒ Object
114 115 116 |
# File 'lib/nendo/ruby/types.rb', line 114 def isDotted ((Cell != @cdr.class) and (Nil != @cdr.class)) end |
#isNull ⇒ Object
118 119 120 |
# File 'lib/nendo/ruby/types.rb', line 118 def isNull ((Nil == @car.class) and (Nil == @cdr.class)) end |
#lastAtom ⇒ Object
128 129 130 131 |
# File 'lib/nendo/ruby/types.rb', line 128 def lastAtom lastOne = self.lastCell lastOne.isDotted end |
#lastCell ⇒ Object
122 123 124 125 126 |
# File 'lib/nendo/ruby/types.rb', line 122 def lastCell lastOne = self self.each { |x| lastOne = x } lastOne end |
#length ⇒ Object
111 |
# File 'lib/nendo/ruby/types.rb', line 111 def length() self.to_arr.length end |
#second ⇒ Object Also known as: cdar
153 154 155 |
# File 'lib/nendo/ruby/types.rb', line 153 def second self.cdr.car end |
#size ⇒ Object
alias of length
112 |
# File 'lib/nendo/ruby/types.rb', line 112 def size() self.length end |
#third ⇒ Object Also known as: cddar
157 158 159 |
# File 'lib/nendo/ruby/types.rb', line 157 def third self.cdr.cdr.car end |
#to_arr ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/nendo/ruby/types.rb', line 141 def to_arr if isNull [] else self.map {|x| x.car} end end |