Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
TEST(0,0)
|
||||
TEST(0,1)
|
||||
TEST(1,0)
|
||||
TEST(1,1)
|
||||
Return
|
||||
|
||||
Lbl TEST
|
||||
r₁→X
|
||||
r₂→Y
|
||||
Disp X▶Hex+3," and ",Y▶Hex+3," = ",(A(X)?B(Y))▶Hex+3,i
|
||||
Disp X▶Hex+3," or ",Y▶Hex+3," = ",(A(X)??B(Y))▶Hex+3,i
|
||||
.Wait for keypress
|
||||
getKeyʳ
|
||||
Return
|
||||
|
||||
Lbl A
|
||||
r₁
|
||||
Return
|
||||
|
||||
Lbl B
|
||||
r₁
|
||||
Return
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function a(p As Boolean) As Boolean
|
||||
Print "a() called"
|
||||
Return p
|
||||
End Function
|
||||
|
||||
Function b(p As Boolean) As Boolean
|
||||
Print "b() called"
|
||||
Return p
|
||||
End Function
|
||||
|
||||
Dim As Boolean i, j, x, y
|
||||
i = False
|
||||
j = True
|
||||
Print "Without short-circuit evaluation :"
|
||||
Print
|
||||
x = a(i) And b(j)
|
||||
y = a(i) Or b(j)
|
||||
Print "x = "; x; " y = "; y
|
||||
Print
|
||||
Print "With short-circuit evaluation :"
|
||||
Print
|
||||
x = a(i) AndAlso b(j) '' b(j) not called as a(i) = false and so x must be false
|
||||
y = a(i) OrElse b(j) '' b(j) still called as can't determine y unless it is
|
||||
Print "x = "; x; " y = "; y
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
function aa bool
|
||||
global outcome
|
||||
put "aa called with" && bool & cr after outcome
|
||||
return bool
|
||||
end aa
|
||||
function b bool
|
||||
global outcome
|
||||
put "b called with" && bool & cr after outcome
|
||||
return bool
|
||||
end b
|
||||
|
||||
on mouseUp
|
||||
global outcome
|
||||
put empty into outcome
|
||||
repeat for each item op in "and,or"
|
||||
repeat for each item x in "true,false"
|
||||
put merge("[[aa(x)]] [[op]] [[b(x)]]") & cr after outcome
|
||||
put merge("[[aa(x)]] [[op]] [[b(not x)]]") & cr after outcome
|
||||
end repeat
|
||||
put cr after outcome
|
||||
end repeat
|
||||
put outcome
|
||||
end mouseUp
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
proc a(x): bool =
|
||||
echo "a called"
|
||||
result = x
|
||||
proc b(x): bool =
|
||||
echo "b called"
|
||||
result = x
|
||||
|
||||
let x = a(false) and b(true) # echoes "a called"
|
||||
|
||||
let y = a(true) or b(true) # echoes "a called"
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
function a(integer i)
|
||||
printf(1,"a ")
|
||||
return i
|
||||
end function
|
||||
|
||||
function b(integer i)
|
||||
printf(1,"b ")
|
||||
return i
|
||||
end function
|
||||
|
||||
for z=0 to 1 do
|
||||
for i=0 to 1 do
|
||||
for j=0 to 1 do
|
||||
if z then
|
||||
printf(1,"a(%d) and b(%d) ",{i,j})
|
||||
printf(1," => %d\n",a(i) and b(j))
|
||||
else
|
||||
printf(1,"a(%d) or b(%d) ",{i,j})
|
||||
printf(1," => %d\n",a(i) or b(j))
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
end for
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
func a(bool) { print 'A'; return bool }
|
||||
func b(bool) { print 'B'; return bool }
|
||||
|
||||
# Test-driver
|
||||
func test() {
|
||||
for op in ['&&', '||'] {
|
||||
for x,y in [[1,1],[1,0],[0,1],[0,0]] {
|
||||
"a(%s) %s b(%s): ".printf(x, op, y)
|
||||
eval "a(Bool(x)) #{op} b(Bool(y))"
|
||||
print "\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Test and display
|
||||
test()
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
func a(v: Bool) -> Bool {
|
||||
print("a")
|
||||
return v
|
||||
}
|
||||
|
||||
func b(v: Bool) -> Bool {
|
||||
print("b")
|
||||
return v
|
||||
}
|
||||
|
||||
func test(i: Bool, j: Bool) {
|
||||
println("Testing a(\(i)) && b(\(j))")
|
||||
print("Trace: ")
|
||||
println("\nResult: \(a(i) && b(j))")
|
||||
|
||||
println("Testing a(\(i)) || b(\(j))")
|
||||
print("Trace: ")
|
||||
println("\nResult: \(a(i) || b(j))")
|
||||
|
||||
println()
|
||||
}
|
||||
|
||||
test(false, false)
|
||||
test(false, true)
|
||||
test(true, false)
|
||||
test(true, true)
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
*!* Visual FoxPro natively supports short circuit evaluation
|
||||
CLEAR
|
||||
CREATE CURSOR funceval(arg1 L, arg2 L, operation V(3), result L, calls V(10))
|
||||
*!* Conjunction
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.F., .F., "AND")
|
||||
REPLACE result WITH (a(arg1) AND b(arg2))
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.F., .T., "AND")
|
||||
REPLACE result WITH (a(arg1) AND b(arg2))
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.T., .F., "AND")
|
||||
REPLACE result WITH (a(arg1) AND b(arg2))
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.T., .T., "AND")
|
||||
REPLACE result WITH (a(arg1) AND b(arg2))
|
||||
*!* Disjunction
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.F., .F., "OR")
|
||||
REPLACE result WITH (a(arg1) OR b(arg2))
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.F., .T., "OR")
|
||||
REPLACE result WITH (a(arg1) OR b(arg2))
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.T., .F., "OR")
|
||||
REPLACE result WITH (a(arg1) OR b(arg2))
|
||||
INSERT INTO funceval (arg1, arg2, operation) VALUES (.T., .T., "OR")
|
||||
REPLACE result WITH (a(arg1) OR b(arg2))
|
||||
GO TOP
|
||||
|
||||
_VFP.DataToClip("funceval", 8, 3)
|
||||
|
||||
FUNCTION a(v As Boolean) As Boolean
|
||||
REPLACE calls WITH "a()"
|
||||
RETURN v
|
||||
ENDFUNC
|
||||
|
||||
FUNCTION b(v As Boolean) As Boolean
|
||||
REPLACE calls WITH calls + ", b()"
|
||||
RETURN v
|
||||
ENDFUNC
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
def a(x): " a(\(x))" | stderr | x;
|
||||
|
||||
def b(y): " b(\(y))" | stderr | y;
|
||||
|
||||
"and:", (a(true) and b(true)),
|
||||
"or:", (a(true) or b(true)),
|
||||
"and:", (a(false) and b(true)),
|
||||
"or:", (a(false) or b(true))
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
$ jq -r -n -f Short-circuit-evaluation.jq
|
||||
and:
|
||||
" a(true)"
|
||||
" b(true)"
|
||||
true
|
||||
or:
|
||||
" a(true)"
|
||||
true
|
||||
and:
|
||||
" a(false)"
|
||||
false
|
||||
or:
|
||||
" a(false)"
|
||||
" b(true)"
|
||||
true
|
||||
Loading…
Add table
Add a link
Reference in a new issue