class Apricot::LetScope

The let scope doesn’t have real storage for locals. It stores its locals on the nearest enclosing real scope, which is any separate block of code such as a fn, defn, defmacro or the top level of the program.

Public Instance Methods

find_recur_target() click to toggle source

A (recur) is looking for a recursion target. This is one only if it is a (loop) form.

# File lib/apricot/scopes.rb, line 155
def find_recur_target
  loop_label ? self : @parent.find_recur_target
end
find_var(name, depth = 0) click to toggle source

An identifier or a nested scope is looking up a variable.

# File lib/apricot/scopes.rb, line 132
def find_var(name, depth = 0)
  if slot = @variables[name]
    LocalReference.new(slot, depth)
  else
    @parent.find_var(name, depth)
  end
end
new_local(name) click to toggle source

Create a new local on the current level, with storage on the nearest enclosing real scope.

# File lib/apricot/scopes.rb, line 142
def new_local(name)
  name = name.name if name.is_a? Identifier
  @variables[name] = @parent.store_new_local(name)
end
store_new_local(name) click to toggle source

A deeper let is asking for a new local slot. Pass it along to the parent so it eventually reaches a real scope.

# File lib/apricot/scopes.rb, line 149
def store_new_local(name)
  @parent.store_new_local(name)
end