 
   _definitionAtScope: (i) ->
     @scopes[i].definition or i > 0 and (@_definitionAtScope i - 1) or undefined
+
+  _deferrableDefinition: ->
+    @_deferrableDefinitionAtScope @scopes.length - 1
+
+  _deferrableDefinitionAtScope: (i) ->
+    (def = @scopes[i].definition) and def.deferrable and def or
+      i > 0 and (@_deferrableDefinitionAtScope i - 1) or undefined
 
   isDefining: ->
     !!@_scope().definition

      []

  doDefer: (expression, dependencyName) ->
    @_setDeferIn @_definition(), expression, dependencyName

  dontDefer: ->
    @_setDeferIn @_definition(), false

  setDeferParent: (dependencyName) ->
    if @scopes.length < 2
      throw new Error "Deferring parent although this is top level scope"
    @_setDeferIn @_parentScope(), dependencyName

  _setDeferIn: (definition, expression, dependencyName) ->
    definition._defer =
      if expression
        (@_deferReasonOf definition) or [expression, dependencyName]
      else
        no

  deferReason: ->
    @_deferReasonOf @_definition()


  newLateScope: ->
    @newScope()
    @_deferrableDefinition()?.late = yes

  closeScope: ->
    @scopes.pop()

  isInsideLateScope: ->
    @_deferrableDefinition()?.late

  isInTopScope: ->
    @_scope().topLevel
