2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,13 @@
# operator to turn two boolean values into an integer - name inspired by the COBOL sample #
PRIO ALSO = 1;
OP ALSO = ( BOOL a, b )INT: IF a AND b THEN 1 ELIF a THEN 2 ELIF b THEN 3 ELSE 4 FI;
# using the above operator, we can use the standard CASE construct to provide the #
# required construct, e.g.: #
BOOL a := TRUE, b := FALSE;
CASE a ALSO b
IN print( ( "both: a and b are TRUE", newline ) )
, print( ( "first: only a is TRUE", newline ) )
, print( ( "second: only b is TRUE", newline ) )
, print( ( "neither: a and b are FALSE", newline ) )
ESAC

View file

@ -0,0 +1,47 @@
function When-Condition
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true, Position=0)]
[bool]
$Test1,
[Parameter(Mandatory=$true, Position=1)]
[bool]
$Test2,
[Parameter(Mandatory=$true, Position=2)]
[scriptblock]
$Both,
[Parameter(Mandatory=$true, Position=3)]
[scriptblock]
$First,
[Parameter(Mandatory=$true, Position=4)]
[scriptblock]
$Second,
[Parameter(Mandatory=$true, Position=5)]
[scriptblock]
$Neither
)
if ($Test1 -and $Test2)
{
return (&$Both)
}
elseif ($Test1 -and -not $Test2)
{
return (&$First)
}
elseif (-not $Test1 -and $Test2)
{
return (&$Second)
}
else
{
return (&$Neither)
}
}

View file

@ -0,0 +1,6 @@
When-Condition -Test1 (Test-Path .\temp.txt) -Test2 (Test-Path .\tmp.txt) `
-Both { "both true"
} -First { "first true"
} -Second { "second true"
} -Neither { "neither true"
}

View file

@ -0,0 +1,8 @@
Set-Alias -Name if2 -Value When-Condition
if2 $true $false {
"both true"
} { "first true"
} { "second true"
} { "neither true"
}

View file

@ -1,23 +1,23 @@
/*REXX program introduces IF2, a type of a four-way compound IF: */
parse arg bot top . /*obtain optional arguments from the CL*/
if bot=='' | bot==',' then bot=10 /*Not specified? Then use the default.*/
if top=='' | top==',' then top=25 /* " " " " " " */
w=max(length(bot), length(top)) + 10 /*W: max width, used for displaying #. */
/*REXX program introduces the IF2 "statement", a type of a four-way compound IF: */
parse arg bot top . /*obtain optional arguments from the CL*/
if bot=='' | bot=="," then bot=10 /*Not specified? Then use the default.*/
if top=='' | top=="," then top=25 /* " " " " " " */
w=max(length(bot), length(top)) + 10 /*W: max width, used for displaying #.*/
do #=bot to top /*put a DO loop through its paces. */
/* [↓] divisible by two and/or three? */
if2( #//2==0, #//3==0) /*use a new four-way IF statement. */
select /*now, test the four possible cases. */
when if.11 then say right(#,w) " is divisible by both two and three."
when if.10 then say right(#,w) " is divisible by two, but not by three."
when if.01 then say right(#,w) " is divisible by three, but not by two."
when if.00 then say right(#,w) " isn't divisible by two, nor by three."
otherwise nop /*◄──┬◄ this statement is optional and */
end /*select*/ /* ├◄ only exists in case one or more*/
end /*#*/ /* └◄ WHENs (above) are omitted. */
exit /*stick a fork in it, we're all 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 ''
do #=bot to top /*put a DO loop through its paces. */
/* [↓] divisible by two and/or three? */
if2( #//2==0, #//3==0) /*use a new four-way IF statement. */
select /*now, test the four possible cases. */
when if.11 then say right(#,w) " is divisible by both two and three."
when if.10 then say right(#,w) " is divisible by two, but not by three."
when if.01 then say right(#,w) " is divisible by three, but not by two."
when if.00 then say right(#,w) " isn't divisible by two, nor by three."
otherwise nop /*◄──┬◄ this statement is optional and */
end /*select*/ /* ├◄ only exists in case one or more*/
end /*#*/ /* └◄ WHENs (above) are omitted. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
if2: parse arg if.10, if.01 /*assign the cases of 10 and 01 */
if.11= if.10 & if.01 /* " " case " 11 */
if.00= \(if.10 | if.01) /* " " " " 00 */
return ''