plow-technologies / inferno

A statically-typed functional scripting language
MIT License
4 stars 1 forks source link

Add some primitives; speed up tests #81

Closed siddharth-krishna closed 1 year ago

siddharth-krishna commented 1 year ago

This PR adds some (long awaited) primitives to Inferno. :)

// Function composition with `<<`, `.` creates parsing issues
assert Array.map ((Text.append "a") << (Text.append "b")) ["0", "1"] == ["ab0", "ab1"] in
// Pipe operator `|>`
assert "0" |> Text.append "a" |> Text.append "b" == "ba0" in
// Some tuple stuff:
assert fst (1, 0) == snd (0, 1) in
assert zip [1, 2, 3] [4, 5] == [(1, 4), (2, 5)] in
assert zip [1, 2] ["a", "b"] == [(1,"a"),(2,"b")] in
assert zip [1] ["a", "b"] == [(1,"a")] in
assert zip [1, 2] ["a"] == [(1,"a")] in
assert zip [] [1, 2] == [] in
assert zip [1, 2] [] == [] in
0

~While adding these, I noticed that the Eval tests were very slow because they were re-evaluating the prelude for each test. This PR also adds a new function evalInEmptyEnv that shares this computation and speeds up the tests by 3x.~ These changes have been split out into a separate PR #82 that has been merged already

Daniel-Diaz commented 1 year ago

I think a solution that should work for both empty and non-empty environments is being able to pass such environment to mkInferno, instead of being generated by it. This would make the run-with-empty-environment function redundant and all evaluations will get the optimization.

siddharth-krishna commented 1 year ago

@Daniel-Diaz I split out the refactor into a separate PR #82 so now this PR is just the new primitives. Let me know if it looks good and we can merge this one in too? Thanks