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 |
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; |
||
⚫ | |||
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|"?"|""); |
||
⚫ | |||
⚫ | |||
⚫ | |||
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((" |
print((" bits: ", bits , " => ", ABS bits /= 0, or, bits /= 2r0, or, |
||
bits width ELEM bits, or, []BOOL(bits)[bits width], new line)); |
|||
print((" |
print((" bytes: """, STRING(bytes) , """ => ", 1 ELEM bytes /= null char, or, |
||
STRING(bytes) /= null char*bytes width, or, |
|||
⚫ | |||
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> |
OD</lang> |
||
Output: |
Output: |
||
<pre> |
<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 |
||
bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF => F or F or F or F |
|||
bytes: "" => F or F or F |
|||
char: "" => F or F |
|||
string: "" => F or F |
|||
TRUE: 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 |
||
bits: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFT => T or T or T or T |
|||
bytes: "????????????????????????????????" => T or T or T |
|||
char: "?" => T or T |
|||
string: "?" => T or T |
|||
</pre> |
</pre> |
||