June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -11,10 +11,10 @@ program =
[
(false, true) forEach(:j)
[
console printLine(i," and ",j," = ",a eval:i && $(b eval:j)).
console printLine(i," and ",j," = ",a(i) && $(b(j))).
console writeLine.
console printLine(i," or ",j," = ",a eval:i || $(b eval:j)).
console printLine(i," or ",j," = ",a(i) || $(b(j))).
console writeLine.
].
].

View file

@ -0,0 +1,14 @@
USING: combinators.short-circuit.smart io prettyprint ;
IN: rosetta-code.short-circuit
: a ( ? -- ? ) "(a)" write ;
: b ( ? -- ? ) "(b)" write ;
"f && f = " write { [ f a ] [ f b ] } && .
"f || f = " write { [ f a ] [ f b ] } || .
"f && t = " write { [ f a ] [ t b ] } && .
"f || t = " write { [ f a ] [ t b ] } || .
"t && f = " write { [ t a ] [ f b ] } && .
"t || f = " write { [ t a ] [ f b ] } || .
"t && t = " write { [ t a ] [ t b ] } && .
"t || t = " write { [ t a ] [ t b ] } || .

View file

@ -1,21 +1,22 @@
function aa bool
global outcome
put "aa called with" && bool & cr after outcome
global outcome
function a bool
put "a called with" && bool & cr after outcome
return bool
end aa
end a
function b bool
global outcome
put "b called with" && bool & cr after outcome
return bool
end b
on mouseUp
global outcome
local tExp
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
put merge("a([[x]]) [[op]] b([[x]])") into tExp
put merge(tExp && "is [[" & tExp & "]]") & cr after outcome
put merge("a([[x]]) [[op]] b([[not x]])") into tExp
put merge(tExp && "is [[" & tExp & "]]") & cr after outcome
end repeat
put cr after outcome
end repeat

View file

@ -0,0 +1,42 @@
MODULE ShortCircuit;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
PROCEDURE a(v : BOOLEAN) : BOOLEAN;
VAR buf : ARRAY[0..63] OF CHAR;
BEGIN
FormatString(" # Called function a(%b)\n", buf, v);
WriteString(buf);
RETURN v
END a;
PROCEDURE b(v : BOOLEAN) : BOOLEAN;
VAR buf : ARRAY[0..63] OF CHAR;
BEGIN
FormatString(" # Called function b(%b)\n", buf, v);
WriteString(buf);
RETURN v
END b;
PROCEDURE Print(x,y : BOOLEAN);
VAR buf : ARRAY[0..63] OF CHAR;
VAR temp : BOOLEAN;
BEGIN
FormatString("a(%b) AND b(%b)\n", buf, x, y);
WriteString(buf);
temp := a(x) AND b(y);
FormatString("a(%b) OR b(%b)\n", buf, x, y);
WriteString(buf);
temp := a(x) OR b(y);
WriteLn;
END Print;
BEGIN
Print(FALSE,FALSE);
Print(FALSE,TRUE);
Print(TRUE,TRUE);
Print(TRUE,FALSE);
ReadChar
END ShortCircuit.

View file

@ -0,0 +1,31 @@
# Project : Short-circuit evaluation
# Date : 2018/01/23
# Author : Gal Zsolt [~ CalmoSoft ~]
# Email : <calmosoft@gmail.com>
for k = 1 to 2
word = ["AND","OR"]
see "========= " + word[k] + " ==============" + nl
for i = 0 to 1
for j = 0 to 1
see "a(" + i + ") " + word[k] +" b(" + j + ")" + nl
res =a(i)
if word[k] = "AND" and res != 0
res = b(j)
ok
if word[k] = "OR" and res = 0
res = b(j)
ok
next
next
next
func a(t)
see char(9) + "calls func a" + nl
a = t
return a
func b(t)
see char(9) + "calls func b" + nl
b = t
return b

View file

@ -0,0 +1,19 @@
fn a(foo: bool) -> bool {
println!("a");
foo
}
fn b(foo: bool) -> bool {
println!("b");
foo
}
fn main() {
for i in vec![true, false] {
for j in vec![true, false] {
println!("{} and {} == {}", i, j, a(i) && b(j));
println!("{} or {} == {}", i, j, a(i) || b(j));
println!();
}
}
}

View file

@ -0,0 +1,24 @@
function a(x) {
printf(" a")
return(x)
}
function b(x) {
printf(" b")
return(x)
}
function call(i, j) {
printf("and:")
x = a(i)
if (x) {
x = b(j)
}
printf("\nor:")
y = a(i)
if (!y) {
y = b(j)
}
printf("\n")
return((x,y))
}

View file

@ -0,0 +1,15 @@
: call(0,1)
and: a
or: a b
1 2
+---------+
1 | 0 1 |
+---------+
: call(1,1)
and: a b
or: a
1 2
+---------+
1 | 1 1 |
+---------+