Boolean values: Difference between revisions

m
m (→‎[[Boolean values#ALGOL 68]]: add the BYTES type.)
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]}}
{{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 commonprinciple conversions:
<lang algol68>BOOL f = FALSE, t = TRUE;
[]BOOL ft = (f, t);
STRING or = " or ";
FOR key TO UPB ft DO
BOOL val = ft[key];
Line 26 ⟶ 27:
REAL real = 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);
STRING string = (val|"?"|"");
BITS bits = bitspack(val);
print((((val | "TRUE" | "FALSE" ), ": ", val, " OR "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((" ref: ", ref ISNT REF STRING(NIL), new line));
Line 36 ⟶ 38:
print((" real: ", real , " => ", real /= 0, new line));
print((" compl: ", compl , " => ", compl /= 0, new line));
print((" charbits: """, charbits , """ => ", ABS char,bits "/= OR0, "or, charbits /= null char2r0, newor, line));
print(("string: """, string , """ => ", string /= "", " OR ", UPB string /= 0 bits width ELEM bits, or, []BOOL(bits)[bits width], new line));
print((" bitsbytes: """, bitsSTRING(bytes) , """ => ", bits width1 ELEM bits,bytes "/= ORnull "char, []BOOL(bits)[bitsor, width]));
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));
TO 2 DO print((new line)) OD
OD</lang>
Output:
<pre>FALSE: F OR F
FALSE: F or F
void: F
ref: F
Line 48 ⟶ 55:
real: +0.00000000000000e +0 => F
compl: +0.00000000000000e +0+0.00000000000000e +0 => F
charbits: ""FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF => F or F or F +0 ORor F
string bytes: "" => F ORor F or F
bitschar: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"" => F ORor F
string: "" => F or F
 
TRUE: T ORor T
void: T
ref: T
Line 58 ⟶ 66:
real: +1.00000000000000e +0 => T
compl: +1.00000000000000e +0+0.00000000000000e +0 => T
charbits: "?"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFT => T or T or T +63 ORor T
string bytes: "????????????????????????????????" => T ORor T or T
bitschar: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFT"?" => T ORor T
string: "?" => T or T
 
</pre>