Anonymous user
Boolean values: Difference between revisions
m
→[[Boolean values#ALGOL 68]]: add the BYTES type.
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
<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 ", (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(("
print(("
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));
OD</lang>
Output:
<pre>
FALSE: F or F
void: F
ref: F
Line 48 ⟶ 55:
real: +0.00000000000000e +0 => F
compl: +0.00000000000000e +0+0.00000000000000e +0 => F
string: "" => F or F
TRUE: T
void: T
ref: T
Line 58 ⟶ 66:
real: +1.00000000000000e +0 => T
compl: +1.00000000000000e +0+0.00000000000000e +0 => T
string: "?" => T or T
</pre>
|