Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -29,4 +29,4 @@ This can be improved by introducing a new keyword '''if2'''. It is similar to ''
|
|||
else
|
||||
noConditionIsTrue();
|
||||
|
||||
Pick the syntax which suits your language. The keywords 'else1' and 'else2' are just examples. The new conditional expression should look, nest and behave analog to the language's built-in 'if' statement.
|
||||
Pick the syntax which suits your language. The keywords 'else1' and 'else2' are just examples. The new conditional expression should look, nest and behave analogously to the language's built-in 'if' statement.
|
||||
|
|
|
|||
20
Task/Extend-your-language/Ada/extend-your-language.ada
Normal file
20
Task/Extend-your-language/Ada/extend-your-language.ada
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Test_If_2 is
|
||||
|
||||
type Two_Bool is range 0 .. 3;
|
||||
|
||||
function If_2(Cond_1, Cond_2: Boolean) return Two_Bool is
|
||||
(Two_Bool(2*Boolean'Pos(Cond_1)) + Two_Bool(Boolean'Pos(Cond_2)));
|
||||
|
||||
begin
|
||||
for N in 10 .. 20 loop
|
||||
Put(Integer'Image(N) & " is ");
|
||||
case If_2(N mod 2 = 0, N mod 3 = 0) is
|
||||
when 2#11# => Put_Line("divisible by both two and three.");
|
||||
when 2#10# => Put_Line("divisible by two, but not by three.");
|
||||
when 2#01# => Put_Line("divisible by three, but not by two.");
|
||||
when 2#00# => Put_Line("neither divisible by two, nor by three.");
|
||||
end case;
|
||||
end loop;
|
||||
end Test_If_2;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
If2[test1_, test2_, condBoth_, cond1_, cond2_, condNone_] := With[
|
||||
{result1 = test1,
|
||||
result2 = test2},
|
||||
Which[
|
||||
result1 && result2, condBoth,
|
||||
result1, cond1,
|
||||
result2, cond2,
|
||||
True, condNone]];
|
||||
SetAttributes[If2, HoldAll];
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
x = 0;
|
||||
If2[Mod[(++x), 2] == 0, Mod[x, 3] == 1, Print["Both: ", x], Print["First: ", x], Print["Second: ", x], Print["Neither: ", x]];
|
||||
If2[Mod[(++x), 2] == 0, Mod[x, 3] == 1, Print["Both: ", x], Print["First: ", x], Print["Second: ", x], Print["Neither: ", x]];
|
||||
If2[Mod[(++x), 2] == 0, Mod[x, 3] == 1, Print["Both: ", x], Print["First: ", x], Print["Second: ", x], Print["Neither: ", x]];
|
||||
If2[Mod[(++x), 2] == 0, Mod[x, 3] == 1, Print["Both: ", x], Print["First: ", x], Print["Second: ", x], Print["Neither: ", x]];
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
if2[c1_,c2_]:=Which[
|
||||
c1&&c2, bothConditionsAreTrue[],
|
||||
c1, firstConditionIsTrue[],
|
||||
c2, secondConditionIsTrue[],
|
||||
True,noConditionIsTrue]
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
if2( some expression that results in a boolean value, some other expression that results in a boolean value.)
|
||||
|
||||
select
|
||||
when if.11 {condition 1 & 2 are true} then perform-a-REXX-statement.
|
||||
when if.10 {condition 1 is true} " " " " "
|
||||
when if.01 {condition 2 is true} " " " " "
|
||||
when if.00 {no condition is true} " " " " "
|
||||
end
|
||||
20
Task/Extend-your-language/REXX/extend-your-language-2.rexx
Normal file
20
Task/Extend-your-language/REXX/extend-your-language-2.rexx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*REXX program introduces IF2, a type of four-way compound IF: */
|
||||
|
||||
do n=10 to 20 /*put DO loop through it's paces.*/
|
||||
/* [↓] divisible by 2 and/or 3? */
|
||||
if2( n//2==0, n//3==0) /*use the four-way IF statement.*/
|
||||
select /*now, test the 4 possible cases.*/
|
||||
when if.11 then say n "is divisible by both two and three."
|
||||
when if.10 then say n "is divisible by two, but not by three."
|
||||
when if.01 then say n "is divisible by three, but not by two."
|
||||
when if.00 then say n "is neither divisible by two, nor by three."
|
||||
otherwise nop /* ◄─┬─this statement is optional*/
|
||||
end /*select*/ /* ├─ and only exists in case */
|
||||
end /*n*/ /* ├─ one or more WHENs (above)*/
|
||||
/* └─ are omitted. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────IF2 routine─────────────────────────*/
|
||||
if2: parse arg if.10, if.01 /*assign the cases 10 and 01 */
|
||||
if.11= if.10 & if.01 /* " " case 11 */
|
||||
if.00= \(if.10 | if.01) /* " " " 00 */
|
||||
return '' /*return to the invoker of IF2. */
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
# Define a class which always returns itself for everything
|
||||
class HopelesslyEgocentric
|
||||
def method_missing what, *args; self; end;
|
||||
def method_missing(what, *args) self end
|
||||
end
|
||||
|
||||
def if2 cond1, cond2
|
||||
def if2(cond1, cond2)
|
||||
if cond1 and cond2
|
||||
yield
|
||||
HopelesslyEgocentric.new
|
||||
elsif cond1
|
||||
Class.new(HopelesslyEgocentric) do
|
||||
def else1; yield; HopelesslyEgocentric.new; end
|
||||
def else1; yield; HopelesslyEgocentric.new end
|
||||
end.new
|
||||
elsif cond2
|
||||
Class.new(HopelesslyEgocentric) do
|
||||
def else2; yield; HopelesslyEgocentric.new; end
|
||||
def else2; yield; HopelesslyEgocentric.new end
|
||||
end.new
|
||||
else
|
||||
Class.new(HopelesslyEgocentric) do
|
||||
def neither; yield; end
|
||||
def neither; yield end
|
||||
end.new
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
if2(5 < x, x < 7) do
|
||||
puts "both true"
|
||||
end.else1 do
|
||||
puts "first is true"
|
||||
end.else2 do
|
||||
puts "second is true"
|
||||
end.neither do
|
||||
puts "neither is true"
|
||||
[true,false].product([true,false]).each do |cond1, cond2|
|
||||
print "%5s, %5s => " % [cond1, cond2]
|
||||
if2(cond1, cond2) do
|
||||
puts "both true"
|
||||
end.else1 do
|
||||
puts "first is true"
|
||||
end.else2 do
|
||||
puts "second is true"
|
||||
end.neither do
|
||||
puts "neither is true"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue