Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit 9bd82ae

Browse files
committed
Update examples/aoc-24/day-01/part_01.lbd
1 parent af91bc8 commit 9bd82ae

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

‎examples/aoc-24/day-01/part_01.lbd‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
-- Problem Link: <https://adventofcode.com/2024/day/1>
22

3-
-- TODO: Use does not work
4-
-- use "examples/std.lbd"
5-
6-
-- NOTE: Copied from examples/std.lbd
7-
true: Bool = \x: Any. \y: Any. x
8-
false: Bool = \x: Any. \y: Any. y
9-
10-
if_then: Any = \condition: Any.
11-
\then_clause: Any. \else_clause: Any.
12-
(condition then_clause else_clause)
13-
14-
lt: Float -> Float -> Bool = \x: Float. \y: Float.
15-
(if_zero (cmp (cmp x y) -1) true false)
16-
--------------------------------------
3+
use "examples/std.lbd"
174

185
content: String = (slurp_file "examples/aoc-24/day-01/input.txt")
196
entries: List = (lines content)
207

21-
-- TODO: Make a general builtin for this
22-
rot_2: Any -> Any -> Any -> Any = \fn: Any. \x: Any. \y: Any. (fn y x)
23-
248
-- TODO: Add support for un-named Lambda Expressions
259
tmp: String -> Any = \x: String. (rot_2 split " " x)
2610
cols: List = (transpose (map tmp entries))
@@ -29,7 +13,6 @@ cols: List = (transpose (map tmp entries))
2913
tmp2: List -> Any = \x: List. (map parse_float x)
3014
lists: List = (map sort (map tmp2 cols))
3115

32-
abs: Float -> Float = \x: Float. (if_then (lt x 0) (mul -1 x) x)
3316
tmp3: List -> Float = \x: List. (abs (sub (list_get x 0) (list_get x 1)))
3417
add2: Float -> Float -> Float = \x: Float. \y: Float. (add y x)
3518
res: Float = (foldr add2 0 (map tmp3 (zip lists)))

‎examples/std.lbd‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ lte: Float -> Float -> Bool = \x: Float. \y: Float.
2828
(if_zero (cmp x y) true (if_zero (cmp (cmp x y) -1) true false))
2929

3030
gte: Float -> Float -> Bool = \x: Float. \y: Float.
31-
(if_zero (cmp x y) true (if_zero (cmp (cmp x y) 1) true false))
31+
(if_zero (cmp x y) true (if_zero (cmp (cmp x y) 1) true false))
32+
33+
-- TODO: Make a general builtin for this
34+
rot_2: Any -> Any -> Any -> Any = \fn: Any. \x: Any. \y: Any. (fn y x)
35+
36+
-- Math
37+
abs: Float -> Float = \x: Float. (if_then (lt x 0) (mul -1 x) x)

‎src/repl.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ namespace repl {
3434
}
3535

3636
fe::parser::Parser parser(tokens, sub_options);
37+
if (sub_options.debug) {
38+
for (const auto &node: parser.program.nodes) {
39+
sub_options.logger.debug(node);
40+
}
41+
}
3742

3843
const std::optional<std::shared_ptr<intp::interp::Env> > temp_env = shared_env;
3944
// Merge loaded_env into shared_env

0 commit comments

Comments
 (0)