Skip to content

Commit 4d819de

Browse files
committed
start env impl
1 parent 012fffe commit 4d819de

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

gleam.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ version = "1.0.0"
1313
# https://gleam.run/writing-gleam/gleam-toml/.
1414

1515
[dependencies]
16-
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
16+
gleam_stdlib = ">= 0.59.0 and < 1.0.0"
1717

1818
[dev-dependencies]
1919
gleeunit = ">= 1.0.0 and < 2.0.0"

manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ packages = [
77
]
88

99
[requirements]
10-
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
10+
gleam_stdlib = { version = ">= 0.59.0 and < 1.0.0" }
1111
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }

src/env.gleam

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import ast.{type Expr}
2+
import gleam/dict
3+
4+
pub type Env =
5+
dict.Dict(String, Expr)
6+
7+
/// Create a new empty environment
8+
pub fn new() -> Env {
9+
dict.new()
10+
}
11+
12+
/// Get a value from the environment
13+
pub fn get(env: Env, key: String) -> Result(Expr, String) {
14+
case dict.get(env, key) {
15+
Ok(value) -> Ok(value)
16+
Error(_) -> Error("Unknown variable: " <> key)
17+
}
18+
}
19+
20+
/// Set a value in the environment
21+
pub fn set(env: Env, key: String, value: Expr) -> Env {
22+
dict.insert(env, key, value)
23+
}

src/eval.gleam

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1+
import ast.{type Expr, Atom, Builtin, List, Number}
2+
import env.{type Env}
3+
import gleam/list

0 commit comments

Comments
 (0)