Merge branch 'next' of github.com:h3rald/min into next
h3rald h3rald@h3rald.com
Mon, 28 Dec 2020 16:28:16 +0100
4 files changed,
73 insertions(+),
2 deletions(-)
M
lib/min_logic.nim
→
lib/min_logic.nim
@@ -138,6 +138,24 @@ raiseInvalid("Result of first quotation is not a boolean value")
if not resB.isBool: raiseInvalid("Result of second quotation is not a boolean value") i.push newVal(resA.boolVal and resB.boolVal) + + def.symbol("expect-all") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + var c = 0 + for v in q.qVal: + if not v.isQuotation: + raiseInvalid("A quotation of quotations is expected") + var vv = v + i.dequote vv + let r = i.pop + c.inc() + if not r.isBool: + raiseInvalid("Quotation #$# does not evaluate to a boolean value") + if not r.boolVal: + i.push r + return + i.push true.newVal def.symbol("or") do (i: In): let vals = i.expect("bool", "bool")@@ -158,9 +176,27 @@ i.dequote(a)
let resA = i.pop if not resA.isBool: raiseInvalid("Result of first quotation is not a boolean value") - if not resB.isBool: + if resB.isBool: raiseInvalid("Result of second quotation is not a boolean value") i.push newVal(resA.boolVal and resB.boolVal) + + def.symbol("expect-any") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + var c = 0 + for v in q.qVal: + if not v.isQuotation: + raiseInvalid("A quotation of quotations is expected") + var vv = v + i.dequote vv + let r = i.pop + c.inc() + if not r.isBool: + raiseInvalid("Quotation #$# does not evaluate to a boolean value") + if r.boolVal: + i.push r + return + i.push false.newVal def.symbol("xor") do (i: In): let vals = i.expect("bool", "bool")@@ -223,5 +259,11 @@ if vals[1].isTypedDictionary(vals[0].getString):
i.push true.newVal else: i.push (vals[1].typename == vals[0].getString).newVal + + def.symbol("&&") do (i: In): + i.push("expect-all".newSym) + + def.symbol("||") do (i: In): + i.push("expect-any".newSym) def.finalize("logic")
M
next-release.md
→
next-release.md
@@ -1,1 +1,3 @@
* **REMOVED** support for creating dynamic libraries (it never worked properly anyway) +* Added **operator** symbol to define symbols and sigils in a more controlled way. +* Added **expect-all** and **expect-any** symbols.
M
site/contents/reference-logic.md
→
site/contents/reference-logic.md
@@ -90,6 +90,14 @@
{#op||dictionary?||{{any}}||{{b}}|| Returns {{t}} if {{any}} is a dictionary, {{f}} otherwise. #} +{#op||expect-all||{{q}}||{{b}}|| +Assuming that {{q}} is a quotation of quotations each evaluating to a boolean value, it pushes {{t}} on the stack if they all evaluate to {{t}}, {{f}} otherwise. + #} + +{#op||expect-any||{{q}}||{{b}}|| +Assuming that {{q}} is a quotation of quotations each evaluating to a boolean value, it pushes {{t}} on the stack if any evaluates to {{t}}, {{f}} otherwise. + #} + {#op||float?||{{any}}||{{b}}|| Returns {{t}} if {{any}} is a float, {{f}} otherwise. #}
M
tests/logic.min
→
tests/logic.min
@@ -151,6 +151,25 @@ (3.3 'test == not) assert
("a" :x (x number?) (x 6 <) dequote-and not) assert (1 :x (x number?) (dsagasdgsg) dequote-or) assert - + + ( + ( + (true) + (2 1 >) + ("a" "b" ==) + ("never printed" puts!) + ) && + false == + ) assert + + ( + ( + (false) + (2 1 <) + ("a" "a" ==) + ("never printed" puts!) + ) || + ) assert + report clear-stack