Class: AjLisp::List
- Inherits:
-
Object
- Object
- AjLisp::List
- Defined in:
- lib/ajlisp/list.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#rest ⇒ Object
readonly
Returns the value of attribute rest.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(context) ⇒ Object
-
#initialize(first = nil, rest = nil) ⇒ List
constructor
A new instance of List.
- #isEqualTo(list) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(first = nil, rest = nil) ⇒ List
Returns a new instance of List.
8 9 10 11 |
# File 'lib/ajlisp/list.rb', line 8 def initialize(first=nil, rest=nil) @first = first @rest = rest end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
5 6 7 |
# File 'lib/ajlisp/list.rb', line 5 def first @first end |
#rest ⇒ Object (readonly)
Returns the value of attribute rest.
6 7 8 |
# File 'lib/ajlisp/list.rb', line 6 def rest @rest end |
Class Method Details
.make(array) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ajlisp/list.rb', line 65 def self.make(array) if array and array.length > 0 first = array.shift if first.is_a? Array first = make(first) elsif first.is_a? Symbol first = NamedAtom.new first end if array.length == 0 return List.new first, nil end return List.new first, make(array) end return nil end |
Instance Method Details
#evaluate(context) ⇒ Object
13 14 15 16 |
# File 'lib/ajlisp/list.rb', line 13 def evaluate(context) form = AjLisp::evaluate(context, @first) form.evaluate(context, self) end |
#isEqualTo(list) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ajlisp/list.rb', line 39 def isEqualTo(list) if not list.is_a? List return false end if @first != list.first if @first.is_a? List or @first.is_a? NamedAtom if !@first.isEqualTo(list.first) return false end else return false end end if @rest == nil and list.rest == nil return true end if @rest.is_a? List return @rest.isEqualTo(list.rest) end return false end |
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ajlisp/list.rb', line 18 def to_s result = "(" first = @first result += AjLisp::to_s(first) rest = @rest while rest result += " " first = rest.first result += AjLisp::to_s(first) rest = rest.rest end result += ")" return result end |