September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Extend-your-language/00META.yaml
Normal file
1
Task/Extend-your-language/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
1
Task/Extend-your-language/Coq/extend-your-language.coq
Normal file
1
Task/Extend-your-language/Coq/extend-your-language.coq
Normal file
|
|
@ -0,0 +1 @@
|
|||
Notation "A /\ B" := (and A B)
|
||||
|
|
@ -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.
|
||||
13
Task/Extend-your-language/Java/extend-your-language-1.java
Normal file
13
Task/Extend-your-language/Java/extend-your-language-1.java
Normal 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();
|
||||
}
|
||||
}
|
||||
15
Task/Extend-your-language/Java/extend-your-language-2.java
Normal file
15
Task/Extend-your-language/Java/extend-your-language-2.java
Normal 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"));
|
||||
}
|
||||
}
|
||||
41
Task/Extend-your-language/Java/extend-your-language-3.java
Normal file
41
Task/Extend-your-language/Java/extend-your-language-3.java
Normal 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;
|
||||
}
|
||||
}
|
||||
14
Task/Extend-your-language/Java/extend-your-language-4.java
Normal file
14
Task/Extend-your-language/Java/extend-your-language-4.java
Normal 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");
|
||||
});
|
||||
91
Task/Extend-your-language/Julia/extend-your-language.julia
Normal file
91
Task/Extend-your-language/Julia/extend-your-language.julia
Normal 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)
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue