Current section
Files
Jump to
Current section
Files
src/glisp@environment.erl
-module(glisp@environment).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/0, get/2, set/3]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC("// A module for managing environments that map variable names to expressions.\n").
-file("src/glisp/environment.gleam", 12).
?DOC(" Create a new empty environment\n").
-spec new() -> gleam@dict:dict(binary(), glisp@ast:expr()).
new() ->
maps:new().
-file("src/glisp/environment.gleam", 17).
?DOC(" Get a value from the environment\n").
-spec get(gleam@dict:dict(binary(), glisp@ast:expr()), binary()) -> {ok,
glisp@ast:expr()} |
{error, binary()}.
get(Env, Key) ->
case gleam_stdlib:map_get(Env, Key) of
{ok, Value} ->
{ok, Value};
{error, _} ->
{error, <<"Unknown variable: "/utf8, Key/binary>>}
end.
-file("src/glisp/environment.gleam", 25).
?DOC(" Set a value in the environment\n").
-spec set(
gleam@dict:dict(binary(), glisp@ast:expr()),
binary(),
glisp@ast:expr()
) -> gleam@dict:dict(binary(), glisp@ast:expr()).
set(Env, Key, Value) ->
gleam@dict:insert(Env, Key, Value).