Browse Source

adding the if function

main
Gil Mizrahi 11 months ago
parent
commit
58d23adffc
2 changed files with 15 additions and 0 deletions
  1. +5
    -0
      src/Language/Logi/Interpreter.hs
  2. +10
    -0
      test/Functions.hs

+ 5
- 0
src/Language/Logi/Interpreter.hs View File

@@ -455,6 +455,11 @@ builtins = M.fromList
(ELit $ LitBool True)
(all (x==) xs)

, Name "if" .= \case
[ELit (LitBool test), tru, fals] ->
pure $ if test then tru else fals
args -> err (Name "if") args

-- strings --
, Name "count" .= \case
[ELit (LitString str)] -> do


+ 10
- 0
test/Functions.hs View File

@@ -60,6 +60,16 @@ tests = do
(runE' ["@avg(1,2,3,4,5,6)"])
(resExpr (rat_ (7%2)))

it "if then" $ do
shouldBe
(runE' ["@if(@lesser(3,5), 'hello', 'world')"])
(resExpr (str_ "hello"))

it "if else" $ do
shouldBe
(runE' ["@if(@greater(3,5), 'hello', 'world')"])
(resExpr (str_ "world"))

it "count 'hello world'" $ do
shouldBe
(runE' ["@count('hello world')"])


Loading…
Cancel
Save