Class Environment

    • Constructor Detail

      • Environment

        public Environment()
    • Method Detail

      • visit

        abstract void visit​(Consumer<Binding> consumer)
        Visits every variable binding in this environment.

        Bindings that are obscured by more recent bindings of the same name are visited, but after the more obscuring bindings.

      • asString

        public String asString()
        Converts this environment to a string.

        This method does not override the Object.toString() method; if we did, debuggers would invoke it automatically, burning lots of CPU and memory.

      • getOpt

        public abstract @Nullable Binding getOpt​(String name)
        Returns the binding of name if bound, null if not.
      • getOpt

        public abstract @Nullable Binding getOpt​(Core.NamedPat id)
        Returns the binding of id if bound, null if not.
      • bind

        public Environment bind​(Core.IdPat id,
                                Object value)
        Creates an environment that is the same as a given environment, plus one more variable.
      • forEachType

        public void forEachType​(BiConsumer<String,​Type> consumer)
        Calls a consumer for each variable and its type. Does not visit obscured bindings.
      • forEachValue

        public void forEachValue​(BiConsumer<String,​Object> consumer)
        Calls a consumer for each variable and its value. Does not visit obscured bindings, or bindings to Unit.INSTANCE.
      • getValueMap

        public final Map<String,​Binding> getValueMap()
        Returns a map of the values and bindings.
      • bindAll

        public final Environment bindAll​(Iterable<Binding> bindings)
        Creates an environment that is the same as this, plus the given bindings.
      • nearestAncestorNotObscuredBy

        abstract Environment nearestAncestorNotObscuredBy​(Set<Core.NamedPat> names)
        If this environment only defines bindings in the given set, returns its parent. Never returns null. The empty environment returns itself.
      • distance

        abstract int distance​(int soFar,
                              Core.NamedPat id)
      • plus

        public Environment plus​(Environment env)
        Returns this environment plus the bindings in the given environment.