Skip to content

Commit

Permalink
add backend_interpreter map
Browse files Browse the repository at this point in the history
  • Loading branch information
y2k committed Dec 31, 2024
1 parent fd48b19 commit def2796
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/backend_interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ module Functions = struct
List.fold_left (fun acc (k, v) -> interpret f [ acc; SBList (unknown_location, [ k; v ]) ]) def_ xs
| n -> failnode __LOC__ [ n ])
| n -> failnode __LOC__ n)
|> StringMap.add "map" (fun interpret -> function
| [ f; xs ] -> (
match xs with
| SBList (m, xs) -> SBList (m, List.map (fun x -> interpret f [ x ]) xs)
| n -> failnode __LOC__ [ n ])
| n -> failnode __LOC__ n)
|> StringMap.add "map?" (fun _ args ->
match args with [ CBList _ ] -> Atom (unknown_location, "true") | _ -> Atom (unknown_location, "false"))
|> StringMap.add "vector?" (fun _ args ->
Expand Down
2 changes: 1 addition & 1 deletion prelude
5 changes: 1 addition & 4 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ let _assert_repl = Utils.assert_ (Lib.main_interpreter true) "interpreter/prelud
let () =
Alcotest.run "Tests"
[
("Local", [
_assert_repl __POS__ {|"he\nwo"|} "he\nwo";
_assert_js __POS__ {|"he\nwo"|} {|"he\nwo"|};
]);
("Local", [ _assert_repl __POS__ {|(map (fn [x] (+ x x)) [1 2 3])|} "[2 4 6]" ]);
("Repl", U.make_samples_test (Lib.main_interpreter true) "interpreter/prelude.clj" "samples.repl");
("Bytecode", U.make_samples_test (Lib.main_bytecode true) "bytecode/prelude.clj" "samples.bytecode");
("JS", U.make_samples_test (Lib.main_js true) "js/src/prelude.clj" "samples.js");
Expand Down

0 comments on commit def2796

Please sign in to comment.