class Lisp::Vector

Public Class Methods

new(a = []) click to toggle source
# File lib/rubylisp/vector.rb, line 10
def initialize(a = [])
  @value = a
  self
end
with_array(a) click to toggle source
# File lib/rubylisp/vector.rb, line 5
def self.with_array(a)
  self.new(a)
end

Public Instance Methods

add(e) click to toggle source
# File lib/rubylisp/vector.rb, line 41
def add(e)
  @value << e
end
at(n) click to toggle source
# File lib/rubylisp/vector.rb, line 56
def at(n)
  @value[n]
end
Also aliased as: nth
at_put(n, d) click to toggle source
# File lib/rubylisp/vector.rb, line 68
def at_put(n, d)
  @value[n] = d
end
each(&block) click to toggle source
# File lib/rubylisp/vector.rb, line 87
def each &block
  @value.each &block
end
empty?() click to toggle source
# File lib/rubylisp/vector.rb, line 31
def empty?
  @value.empty?
end
equal?(other) click to toggle source
# File lib/rubylisp/vector.rb, line 78
def equal?(other)
  return false unless other.vector?
  return false unless @value.size == other.value.size
  (0..@value.size).each do |i|
    return false unless other.value[i].equal?(value[i])
  end
  true
end
length() click to toggle source
# File lib/rubylisp/vector.rb, line 36
def length
  @value.size
end
nth(n)
Alias for: at
nth_tail(n) click to toggle source
# File lib/rubylisp/vector.rb, line 62
def nth_tail(n)
  return Lisp::Vector.new if n > @value.size
  Lisp::Vector.new(@value[n..-1])
end
set_nth!(n, d) click to toggle source
# File lib/rubylisp/vector.rb, line 73
def set_nth!(n, d)
  at_put(n, d)
end
to_a() click to toggle source
# File lib/rubylisp/vector.rb, line 46
def to_a
  @value
end
to_s() click to toggle source
# File lib/rubylisp/vector.rb, line 51
def to_s
  "#(#{@value.join(' ')})"
end
type() click to toggle source
# File lib/rubylisp/vector.rb, line 20
def type
  :vector
end
update!(a) click to toggle source
# File lib/rubylisp/vector.rb, line 16
def update!(a)
  @value = a
end
vector?() click to toggle source
# File lib/rubylisp/vector.rb, line 25
def vector?
  true
end