Boolean values: Difference between revisions

Content added Content deleted
m (→‎[[Boolean values#ALGOL 68]]: add the BYTES type.)
Line 16: Line 16:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - note: null char is missing, AND the C generated is won't compile, so some conversions are missing from RS}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - note: null char is missing, AND the C generated is won't compile, so some conversions are missing from RS}}
ALGOL 68 Enforces strong typing and so has few default coersions. The appropriate operators must be used to convert to and from BOOLean. The following code demonstrates common conversions:
ALGOL 68 Enforces strong typing and so has few default coersions. The appropriate operators must be used to convert to and from BOOLean. The following code demonstrates principle conversions:
<lang algol68>BOOL f = FALSE, t = TRUE;
<lang algol68>BOOL f = FALSE, t = TRUE;
[]BOOL ft = (f, t);
[]BOOL ft = (f, t);
STRING or = " or ";
FOR key TO UPB ft DO
FOR key TO UPB ft DO
BOOL val = ft[key];
BOOL val = ft[key];
Line 26: Line 27:
REAL real = ABS val;
REAL real = ABS val;
COMPL compl = ABS val;
COMPL compl = ABS val;
BITS bits = BIN ABS val; # or bitspack(val); #
BYTES bytes = bytes pack((val|"?"|null char)*bytes width);
CHAR char = (val|"?"|null char);
CHAR char = (val|"?"|null char);
STRING string = (val|"?"|"");
STRING string = (val|"?"|"");
BITS bits = bitspack(val);
print((((val | "TRUE" | "FALSE" ), ": ", val, or, (val|flip|flop), new line)));

print((((val | "TRUE" | "FALSE" ), ": ", val, " OR ", (val|flip|flop), new line)));
print((" void: ", (void|(VOID):FALSE|TRUE), new line));
print((" void: ", (void|(VOID):FALSE|TRUE), new line));
print((" ref: ", ref ISNT REF STRING(NIL), new line));
print((" ref: ", ref ISNT REF STRING(NIL), new line));
Line 36: Line 38:
print((" real: ", real , " => ", real /= 0, new line));
print((" real: ", real , " => ", real /= 0, new line));
print((" compl: ", compl , " => ", compl /= 0, new line));
print((" compl: ", compl , " => ", compl /= 0, new line));
print((" char: """, char , """ => ", ABS char, " OR ", char /= null char, new line));
print((" bits: ", bits , " => ", ABS bits /= 0, or, bits /= 2r0, or,
print(("string: """, string , """ => ", string /= "", " OR ", UPB string /= 0, new line));
bits width ELEM bits, or, []BOOL(bits)[bits width], new line));
print((" bits: ", bits , " => ", bits width ELEM bits, " OR ", []BOOL(bits)[bits width]));
print((" bytes: """, STRING(bytes) , """ => ", 1 ELEM bytes /= null char, or,
STRING(bytes) /= null char*bytes width, or,
TO 2 DO print((new line)) OD
STRING(bytes)[1] /= null char, new line));
print((" char: """, char , """ => ", ABS char /= 0 , or, char /= null char, new line));
print(("string: """, string , """ => ", string /= "", or, UPB string /= 0, new line));
print((new line))
OD</lang>
OD</lang>
Output:
Output:
<pre>FALSE: F OR F
<pre>
FALSE: F or F
void: F
void: F
ref: F
ref: F
Line 48: Line 55:
real: +0.00000000000000e +0 => F
real: +0.00000000000000e +0 => F
compl: +0.00000000000000e +0+0.00000000000000e +0 => F
compl: +0.00000000000000e +0+0.00000000000000e +0 => F
char: "" => +0 OR F
bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF => F or F or F or F
string: "" => F OR F
bytes: "" => F or F or F
bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF => F OR F
char: "" => F or F
string: "" => F or F


TRUE: T OR T
TRUE: T or T
void: T
void: T
ref: T
ref: T
Line 58: Line 66:
real: +1.00000000000000e +0 => T
real: +1.00000000000000e +0 => T
compl: +1.00000000000000e +0+0.00000000000000e +0 => T
compl: +1.00000000000000e +0+0.00000000000000e +0 => T
char: "?" => +63 OR T
bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFT => T or T or T or T
string: "?" => T OR T
bytes: "????????????????????????????????" => T or T or T
bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFT => T OR T
char: "?" => T or T
string: "?" => T or T

</pre>
</pre>