diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-10-05 15:20:20 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-10-05 15:20:20 -0700 |
| commit | b11d0752dbdf963183b3f85d42ade0e5cb7f8eae (patch) | |
| tree | c3a6b153b53deca1c467977efdb80ee6c137b775 /lib | |
| parent | 4ae64ef9e34956235f8b5e2b60c1c8efaa7b913f (diff) | |
Added ternary unless.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/operators.nom | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/operators.nom b/lib/operators.nom index 85332a1..13e6ce4 100644 --- a/lib/operators.nom +++ b/lib/operators.nom @@ -12,14 +12,19 @@ compile [phi, PHI, golden ratio] to: "((1+math.sqrt(5))/2)" compile [nop, pass] to code: "" # Ternary operator -compile [%if_expr if %condition else %else_expr] to: ".." +compile [..] + %when_true_expr if %condition else %when_false_expr + %when_true_expr if %condition otherwise %when_false_expr + %when_false_expr unless %condition else %when_true_expr + %when_false_expr unless %condition then %when_true_expr +..to: ".." #.. Note: this uses a function instead of (condition and if_expr or else_expr) because that breaks if %if_expr is falsey. |(function(nomsu, vars) | if \(%condition as lua) then; - | return \(%if_expr as lua); + | return \(%when_true_expr as lua); | else; - | return \(%else_expr as lua); + | return \(%when_false_expr as lua); | end; |end)(nomsu, vars) |
