clj_scope
Nested scopes.
Implements nested scopes through nested maps. This is heavily used in all throughout the compilation process, from the reader to the emitter.Summary
Types
Functions
-
contains(Key, Scope)
Checks whether
Keyis in the current scope. -
get(Key, Scope)
Equivalent to
get(Key, undefined, Scope). -
get(Key, Default, Scope)
Gets a value from the current scope or
Defaultif not found. -
new()
Creates a new empty scope.
-
new(Parent)
Creates a scope with an assigned parent.
-
parent(Scope)
Returns the parent of the current scope.
-
put(Map, Scope)
Adds all values in
Mapto the current scope. -
put(Key, Value, Scope)
Adds a value to the current scope.
-
to_map(Fun, Scope)
Merges all mappings and returns them in a single map.
-
update(Key, Value, Scope)
Updates the value for
Keyif it is in the current scope or any of its parent scopes. -
values(Scope)
Returns all values in the current scope and all its parent scopes.
Types
scope()
-type scope() :: #{parent => scope() | undefined, mappings => map()}.
Functions
contains(Key, Scope)
-spec contains(any(), scope()) -> boolean().
Checks whether Key is in the current scope.
get(Key, Scope)
-spec get(any(), scope()) -> any().
Equivalent to get(Key, undefined, Scope).
get(Key, Default, Scope)
-spec get(any(), any(), scope()) -> any().
Gets a value from the current scope or Default if not
found.
new()
-spec new() -> scope().
Creates a new empty scope.
new(Parent)
-spec new(scope() | undefined) -> scope().
Creates a scope with an assigned parent.
parent(Scope)
-spec parent(scope()) -> scope() | undefined.
Returns the parent of the current scope.
put(Map, Scope)
-spec put(map(), scope()) -> scope().
Adds all values in Map to the current scope.
put(Key, Value, Scope)
-spec put(any(), any(), scope()) -> scope().
Adds a value to the current scope.
to_map(Fun, Scope)
-spec to_map(function(), scope()) -> any().
Merges all mappings and returns them in a single map.
update(Key, Value, Scope)
-spec update(any(), any(), scope()) -> scope() | not_found.
Updates the value for Key if it is in the current scope or
any of its parent scopes.
values(Scope)
-spec values(scope()) -> [any()].
Returns all values in the current scope and all its parent scopes.