This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,13 @@
1 < 2;
# true
2 < 1;
# false
# GAP has also the value fail, which cannot be used as a boolean but may be used i$
1 = fail;
# false
fail = fail;
# true

View file

@ -0,0 +1 @@
let B be whether or not 123 is greater than 100;

View file

@ -0,0 +1 @@
if B is true, say "123 is greater than 100."

View file

@ -0,0 +1,9 @@
To decide whether the CPU is working correctly:
if 123 is greater than 100, decide yes;
otherwise decide no.
When play begins:
[convert to truth state...]
let B be whether or not the CPU is working correctly;
[...or use as a condition]
if the CPU is working correctly, say "Whew."

View file

@ -0,0 +1,4 @@
#Boolean and conditional expressions only accept 'true' or 'false'
#Convert a number or numeric array to boolean
bool(x)

View file

@ -0,0 +1,4 @@
print 1 < 0 ; false
print 1 > 0 ; true
if "true [print "yes] ; yes
if not "false [print "no] ; no

View file

@ -0,0 +1,3 @@
if equal? 0 ln 1 [print "zero]
if empty? [] [print "empty] ; empty list
if empty? "|| [print "empty] ; empty word

View file

@ -0,0 +1,11 @@
is(1 < 2);
/* true */
is(2 < 1);
/* false */
not true;
/* false */
not false;
/* true */

View file

@ -0,0 +1,28 @@
import java.util.ArrayList
import java.util.HashMap
# booleans
puts 'true is true' if true
puts 'false is false' if (!false)
# lists treated as booleans
x = ArrayList.new
puts "empty array is true" if x
x.add("an element")
puts "full array is true" if x
puts "isEmpty() is false" if !x.isEmpty()
# maps treated as booleans
map = HashMap.new
puts "empty map is true" if map
map.put('a', '1')
puts "full map is true" if map
puts "size() is 0 is false" if !(map.size() == 0)
# these things do not compile
# value = nil # ==> cannot assign nil to Boolean value
# puts 'nil is false' if false == nil # ==> cannot compare boolean to nil
# puts '0 is false' if (0 == false) # ==> cannot compare int to false
#puts 'TRUE is true' if TRUE # ==> TRUE does not exist
#puts 'FALSE is false' if !FALSE # ==> FALSE does not exist

View file

@ -0,0 +1,17 @@
MODULE boo;
IMPORT InOut;
VAR result, done : BOOLEAN;
A, B : INTEGER;
BEGIN
result := (1 = 2);
result := NOT result;
done := FALSE;
REPEAT
InOut.ReadInt (A);
InOut.ReadInt (B);
done := A > B
UNTIL done
END boo.

View file

@ -0,0 +1 @@
TYPE BOOLEAN = {FALSE, TRUE}