Skip to content

Commit 9ad9b2a

Browse files
committed
fixed else if error in life
1 parent b175a8d commit 9ad9b2a

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ The *if()* function takes a boolean expression, a call/statement to execute if t
746746

747747
The *ifs()* function takes a series of arguments that go by the pattern of one bool expression and one execution to process. The list of arguments should thus be even. This function will execute every statement that has a boolean expression that evaluates to true. Every boolean expression that does not evaluate to true will not be executed.
748748

749+
The *ifs()* is meant to act as an advanced switch statement that works on boolean expressions as opposed to pure pattern matching.
750+
749751

750752
```
751753
>> =(d, 33)
@@ -759,4 +761,17 @@ undefined
759761
undefined
760762
>> do(d)
761763
34
764+
```
765+
766+
###ife(bool_exp, true\_call..., else\_call)
767+
768+
The *ife()* function works similarly to the *ifs()* function except it executes one and only one statement. Meaning, it will go through each boolean expression, checking if it is true, and if it is, will execute that statement and stop looking through the other pairs. If none of the pairs are true, it executes the else call.
769+
770+
```
771+
ife(
772+
>(len(lst), 2), put(lst, true),
773+
==(len(lst), 0), append(lst, list(2)),
774+
!=(len(lst), 0), append(lst, 3),
775+
$(`all false`)
776+
)
762777
```

Tests/testsconds.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ t.compileTest("if(==(3, 7), $(8), $(4))", "if(3 === 7){console.log(8);} else{con
1515
t.compileTest("ifs(true, return(1, 2), ==(3, 3), $(4))", "if(true){return [1, 2];};if(3 === 3){console.log(4);};", 10);
1616
t.compileTest("switch(b, 4, $(3), 5, $(4), true, $(1, 2))", "switch(b){case 4: console.log(3);break;case 5: console.log(4);break;case true: console.log(1, 2);break;};", 11);
1717
t.compileTest("ife(==(3, 3), return(3), !=(3, true), $(1, 2, 3, 4), return(list(1, 2, 3)))", "if(3 === 3){return 3;};else if(3 !== true){console.log(1, 2, 3, 4);};else{return [1, 2, 3];};", 12);
18-
t.compileTest("?(true, ?(3, $(1, 2, 3)))", "if(true){if(3){console.log(1, 2, 3);};};", 13);
18+
t.compileTest("?(true, ?(3, $(1, 2, 3)))", "if(true){if(3){console.log(1, 2, 3);};};", 13);
19+
t.compileTest("ife(>(len(lst), 2), put(lst, true),==(len(lst), 0), append(lst, list(2)),!=(len(lst), 0), append(lst, 3),$(`all false`))", "", 15);

builds/WebMain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ var STD = {
499499
condmode = false;
500500
}
501501
else {
502-
str += callLib(this, args[i], args[i+1]) + "};";
502+
str += callLib(this, args[i], args[i+1]) + "}";
503503
condmode = true;
504504
}
505505
}

src/stdlib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ var STD = {
377377
condmode = false;
378378
}
379379
else {
380-
str += callLib(this, args[i], args[i+1]) + "};";
380+
str += callLib(this, args[i], args[i+1]) + "}";
381381
condmode = true;
382382
}
383383
}

0 commit comments

Comments
 (0)