class Lisp::Frame

Public Class Methods

new(m = {}) click to toggle source
# File lib/rubylisp/frame.rb, line 9
def initialize(m = {})
  @value = m
  self
end
with_map(m) click to toggle source
# File lib/rubylisp/frame.rb, line 5
def self.with_map(m)
  self.new(m)
end

Public Instance Methods

at_put(key, value) click to toggle source
# File lib/rubylisp/frame.rb, line 96
def at_put(key, value)
  return @value[key] = value
end
car() click to toggle source
# File lib/rubylisp/frame.rb, line 121
def car
  nil
end
cdr() click to toggle source
# File lib/rubylisp/frame.rb, line 125
def cdr
  nil
end
clone() click to toggle source
# File lib/rubylisp/frame.rb, line 15
def clone
  Lisp::Frame.with_map(@value.clone)
end
empty?() click to toggle source
# File lib/rubylisp/frame.rb, line 109
def empty?
  @value.empty?
end
equal?(other) click to toggle source
# File lib/rubylisp/frame.rb, line 129
def equal?(other)
  return false unless other.frame?
  return false unless @value.length == other.value.length
  @value.each do |k, v|
    return false unless other.value[k].equal?(v)
  end
  true
end
frame?() click to toggle source
# File lib/rubylisp/frame.rb, line 113
def frame?
  true
end
get(key) click to toggle source
# File lib/rubylisp/frame.rb, line 84
def get(key)
  get_helper(key, Set.new)
end
get_helper(key, v) click to toggle source
# File lib/rubylisp/frame.rb, line 72
def get_helper(key, v)
  return nil if v.include?(self)
  v << self
  return @value[key] if has_slot_locally?(key)
  parents.each do |p|
    value = p.get_helper(key, v)
    return value unless value.nil?
  end
  nil
end
has_parent_slots?() click to toggle source
# File lib/rubylisp/frame.rb, line 38
def has_parent_slots?
  @value.keys.any? {|k| is_parent_key(k)}
end
has_slot?(n) click to toggle source
# File lib/rubylisp/frame.rb, line 67
def has_slot?(n)
  has_slot_helper(n, Set.new)
end
has_slot_helper(n, v) click to toggle source
# File lib/rubylisp/frame.rb, line 58
def has_slot_helper(n, v)
  return false if v.include?(self)
  v << self
  return true if has_slot_locally?(n)
  return false unless has_parent_slots?
  return parents.any? {|p| p.has_slot_helper(n, v)}
end
has_slot_locally?(n) click to toggle source
# File lib/rubylisp/frame.rb, line 53
def has_slot_locally?(n)
  @value.has_key?(n)
end
inherited_value_slots() click to toggle source
# File lib/rubylisp/frame.rb, line 30
def inherited_value_slots
  parent_frames = parent_slots.collect {|pk| get(pk)}
  parent_slots = parent_frames.collect {|p| p.inherited_value_slots}
  local_value_slots = Set[local_slots.reject {|s| is_parent_key(k)}]
  parent_slots.inject(local_value_slots) {|all, s| all + s} 
end
is_parent_key(k) click to toggle source
# File lib/rubylisp/frame.rb, line 20
def is_parent_key(k)
  k.to_s[-2] == "*"
end
length() click to toggle source
# File lib/rubylisp/frame.rb, line 117
def length
  return @value.length
end
lisp_object?() click to toggle source
# File lib/rubylisp/frame.rb, line 101
def lisp_object?
  true
end
local_slots() click to toggle source
# File lib/rubylisp/frame.rb, line 25
def local_slots
  @value.keys
end
parent_slots() click to toggle source
# File lib/rubylisp/frame.rb, line 43
def parent_slots
  @value.keys.select {|k| is_parent_key(k)}
end
parents() click to toggle source
# File lib/rubylisp/frame.rb, line 48
def parents
  parent_slots.collect {|pk| @value[pk]}
end
remove(key) click to toggle source
# File lib/rubylisp/frame.rb, line 89
def remove(key)
  return false unless has_slot_locally?(key)
  @value.delete(key)
  true
end
to_s() click to toggle source
# File lib/rubylisp/frame.rb, line 138
def to_s
  pairs = @value.collect {|k, v| "#{k.to_s} #{v.to_s}"}
  "{#{pairs.join(' ')}}"
end
type() click to toggle source
# File lib/rubylisp/frame.rb, line 105
def type
  :frame
end