September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1 @@
--- {}

View file

@ -0,0 +1 @@
Notation "A /\ B" := (and A B)

View file

@ -0,0 +1,24 @@
program fourWay(input, output, stdErr);
var
tuple: record
A: boolean;
B: char;
end;
begin
tuple.A := true;
tuple.B := 'Z';
case tuple of
(A: false; B: 'R'):
begin
writeLn('R is not good');
end;
(A: true; B: 'Z'):
begin
writeLn('Z is great');
end;
else
begin
writeLn('No');
end;
end;
end.

View file

@ -0,0 +1,13 @@
public class If2 {
public static void if2(boolean firstCondition, boolean secondCondition,
Runnable bothTrue, Runnable firstTrue, Runnable secondTrue, Runnable noneTrue) {
if (firstCondition)
if (secondCondition)
bothTrue.run();
else firstTrue.run();
else if (secondCondition)
secondTrue.run();
else noneTrue.run();
}
}

View file

@ -0,0 +1,15 @@
import static If2.if2;
class Main {
private static void print(String s) {
System.out.println(s);
}
public static void main(String[] args) {
// prints "both true"
if2(true, true,
() -> print("both true"),
() -> print("first true"),
() -> print("second true"),
() -> print("none true"));
}
}

View file

@ -0,0 +1,41 @@
public class If2 {
private final boolean firstCondition;
private final boolean secondCondition;
public If2(boolean firstCondition, boolean secondCondition) {
this.firstCondition = firstCondition;
this.secondCondition = secondCondition;
}
public static If2 if2(boolean firstCondition, boolean secondCondition) {
return new If2(firstCondition, secondCondition);
}
public If2 then(Runnable runnable) {
if (firstCondition && secondCondition) {
runnable.run();
}
return this;
}
public If2 elseNone(Runnable runnable) {
if (!firstCondition && !secondCondition) {
runnable.run();
}
return this;
}
public If2 elseIfFirst(Runnable runnable) {
if (firstCondition && !secondCondition) {
runnable.run();
}
return this;
}
public If2 elseIfSecond(Runnable runnable) {
if (!firstCondition && secondCondition) {
runnable.run();
}
return this;
}
}

View file

@ -0,0 +1,14 @@
// prints "both true"
if2(true, true)
.then(() -> print("both true"))
.elseIfFirst(() -> print("first true"))
.elseIfSecond(() -> print("second true"))
.elseNone(() -> print("none true"));
// if we only care about both true and none true...
// prints "none true"
if2(false, false)
.then(() -> print("both true"))
.elseNone(() -> { // a lambda can have a block body
print("none true");
});

View file

@ -0,0 +1,91 @@
const CSTACK1 = Array{Bool,1}()
const CSTACK2 = Array{Bool,1}()
const CSTACK3 = Array{Bool,1}()
macro if2(condition1, condition2, alltrue)
if !(length(CSTACK1) == length(CSTACK2) == length(CSTACK3))
throw("prior if2 statement error: must have if2, elseif1, elseif2, and elseifneither")
end
ifcond1 = eval(condition1)
ifcond2 = eval(condition2)
if ifcond1 && ifcond2
eval(alltrue)
push!(CSTACK1, false)
push!(CSTACK2, false)
push!(CSTACK3, false)
elseif ifcond1
push!(CSTACK1, true)
push!(CSTACK2, false)
push!(CSTACK3, false)
elseif ifcond2
push!(CSTACK1, false)
push!(CSTACK2, true)
push!(CSTACK3, false)
else
push!(CSTACK1, false)
push!(CSTACK2, false)
push!(CSTACK3, true)
end
end
macro elseif1(block)
quote
if pop!(CSTACK1)
$block
end
end
end
macro elseif2(block)
quote
if pop!(CSTACK2)
$block
end
end
end
macro elseifneither(block)
quote
if pop!(CSTACK3)
$block
end
end
end
# Testing of code starts here
@if2(2 != 4, 3 != 7, begin x = "all"; println(x) end)
@elseif1(begin println("one") end)
@elseif2(begin println("two") end)
@elseifneither(begin println("neither") end)
@if2(2 != 4, 3 == 7, println("all"))
@elseif1(begin println("one") end)
@elseif2(begin println("two") end)
@elseifneither(begin println("neither") end)
@if2(2 == 4, 3 != 7, begin x = "all"; println(x) end)
@elseif1(begin println("one") end)
@elseif2(begin println("two") end)
@elseifneither(begin println("neither") end)
@if2(2 == 4, 3 == 7, println("last all") end)
@elseif1(begin println("one") end)
@elseif2(begin println("two") end)
@elseifneither(begin println("neither") end)

View file

@ -0,0 +1,10 @@
10 DEF FN i()=((NOT (a OR b))+2*(a AND NOT b)+3*(b AND NOT a)+4*(a AND b)): REM the function can be placed anywhere in the program, but it gets executed faster if it's at the top
20 FOR x=1 TO 20
30 LET a=(x/2)=INT (x/2): REM comparison 1
40 LET b=(x/3)=INT (x/3): REM comparison 2
50 GO TO 50+10*FN i(): REM cases
60 PRINT x;" is not divisible by 2 or 3": GO TO 100
70 PRINT x;" is divisible by 2": GO TO 100
80 PRINT x;" is divisible by 3": GO TO 100
90 PRINT x;" is divisible by 2 and 3"
100 NEXT x