From f24876c4b51ae6d3dda134bdec441b7ab7547b1d Mon Sep 17 00:00:00 2001 From: Kharec Date: Mon, 9 Mar 2026 19:24:15 +0100 Subject: [PATCH] feat: eliminate redundant dict creation --- src/simple_repl.gleam | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/simple_repl.gleam b/src/simple_repl.gleam index 9bf8a1e..6033937 100644 --- a/src/simple_repl.gleam +++ b/src/simple_repl.gleam @@ -52,22 +52,23 @@ fn append_history(cmd: String) -> Nil { } } -fn repl_loop() -> a { +fn repl_loop(cmds: dict.Dict(String, fn() -> Nil)) -> a { let cmd = get_line("repl> ") |> string.trim cmd |> append_history - case dict.get(commands(), cmd) { + case dict.get(cmds, cmd) { Ok(func) -> func() Error(_) -> io.println(cmd <> ": unknown command") } - repl_loop() + repl_loop(cmds) } pub fn main() -> Nil { + let cmds = commands() case simplifile.is_file(history_file) { - Ok(True) -> repl_loop() + Ok(True) -> repl_loop(cmds) _ -> case simplifile.create_file(history_file) { - Ok(Nil) -> repl_loop() + Ok(Nil) -> repl_loop(cmds) Error(e) -> io.println(simplifile.describe_error(e)) } }