home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sa104os2.zip
/
SATHR104.ZIP
/
SATHER
/
LIBRARY
/
BOOL.SA
< prev
next >
Wrap
Text File
|
1995-02-05
|
7KB
|
178 lines
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
-- bool.sa: Boolean values.
-------------------------------------------------------------------
value class BOOL is
-- BOOL objects represent boolean values and are either equal to
-- `true' or `false'. The boolean operators `and' and `or' are
-- part of the Sather language. This class defines several
-- additional operators.
not:SAME is
-- The complement of self.
-- if self then return false else return true end
raise "BOOL::not:SAME undefined." end;
xnor(b:SAME):SAME is
-- True if self and `b' have the same value (same as "is_eq").
return self=b end;
is_eq(b:SAME):SAME is
-- True if self and `b' have the same value (same as "xnor").
raise "BOOL::is_eq(BOOL):BOOL undefined"; end;
xor(b:SAME):SAME is
-- Self exclusive ored with `b'. Same as "is_neq".
return self/=b end;
is_neq(b:SAME):SAME is
-- True if self and `b' have the same value (same as "xor").
raise "BOOL::is_neq(BOOL):BOOL undefined"; end;
nand(b:SAME):SAME is
-- The complement of self anded with `b'.
return ~(self and b) end;
nor(b:SAME):SAME is
-- The complement of self ored with `b'.
return ~(self or b) end;
implies(b:SAME):SAME is
-- True iff self implies `b'. Same as "nand_not".
return not or b end;
and_rout(b:SAME):SAME is
-- A routine version of "self and `b'". (Useful for making
-- bound routines.)
return self and b end;
or_rout(b:SAME):SAME is
-- A routine version of "self or `b'". (Useful for making
-- bound routines.)
return self or b end;
and_not(b:SAME):SAME is
-- Computes self and the complement of `b'.
return self and ~b end;
or_not(b:SAME):SAME is
-- Computes self or the complement of `b'.
return self or ~b end;
nand_not(b:SAME):SAME is
-- Computes self nand the complement of `b'. This is the same as
-- the complement of self or `b'.
return not or b end;
nor_not(b:SAME):SAME is
-- Computes self nor the complement of `b'. This is the same as
-- the complement of self and `b'.
return not and b end;
str:STR is
-- The string representation of self.
-- if self then return "true" else return "false" end end; -- NLP
if self then return "true"; end; return "false"; end; -- NLP
from_str(s:STR):SAME is
case s
when "true","t","True","T","TRUE" then return true;
when "false","f","False","F","FALSE" then return false;
else raise "Can't interpret bool value: "+s;
end;
return false; -- NLP
end;
end; -- value class BOOL
-------------------------------------------------------------------
class TEST_BOOL is
-- Test of BOOL.
include TEST;
main is
-- Test of BOOL.
class_name("BOOL");
test("false.not", false.not.str, "true");
test("true.not", true.not.str, "false");
test("false and false", (false and false).str, "false");
test("false and true", (false and true).str, "false");
test("true and false", (true and false).str, "false");
test("true and true", (true and true).str, "true");
test("false or false", (false or false).str, "false");
test("false or true", (false or true).str, "true");
test("true or false", (true or false).str, "true");
test("true or true", (true or true).str, "true");
test("false.xor(false)", (false.xor(false)).str, "false");
test("false.xor(true)", (false.xor(true)).str, "true");
test("true.xor(false)", (true.xor(false)).str, "true");
test("true.xor(true)", (true.xor(true)).str, "false");
test("false.xnor(false)", (false.xnor(false)).str, "true");
test("false.xnor(true)", (false.xnor(true)).str, "false");
test("true.xnor(false)", (true.xnor(false)).str, "false");
test("true.xnor(true)", (true.xnor(true)).str, "true");
test("false.nand(false)", (false.nand(false)).str, "true");
test("false.nand(true)", (false.nand(true)).str, "true");
test("true.nand(false)", (true.nand(false)).str, "true");
test("true.nand(true)", (true.nand(true)).str, "false");
test("false.nor(false)", (false.nor(false)).str, "true");
test("false.nor(true)", (false.nor(true)).str, "false");
test("true.nor(false)", (true.nor(false)).str, "false");
test("true.nor(true)", (true.nor(true)).str, "false");
test("false.implies(false)", (false.implies(false)).str, "true");
test("false.implies(true)", (false.implies(true)).str, "true");
test("true.implies(false)", (true.implies(false)).str, "false");
test("true.implies(true)", (true.implies(true)).str, "true");
test("false.and_rout(false)", false.and_rout(false).str, "false");
test("false.and_rout(true)", false.and_rout(true).str, "false");
test("true.and_rout(false)", true.and_rout(false).str, "false");
test("true.and_rout(true)", true.and_rout(true).str, "true");
test("false.or_rout(false)", false.or_rout(false).str, "false");
test("false.or_rout(true)", false.or_rout(true).str, "true");
test("true.or_rout(false)", true.or_rout(false).str, "true");
test("true.or_rout(true)", true.or_rout(true).str, "true");
test("false.nor_not(false)", false.nor_not(false).str, "false");
test("false.nor_not(true)", false.nor_not(true).str, "true");
test("true.nor_not(false)", true.nor_not(false).str, "false");
test("true.nor_not(true)", true.nor_not(true).str, "false");
test("false.and_not(false)", false.and_not(false).str, "false");
test("false.and_not(true)", false.and_not(true).str, "false");
test("true.and_not(false)", true.and_not(false).str, "true");
test("true.and_not(true)", true.and_not(true).str, "false");
test("false.nand_not(false)", false.nand_not(false).str, "true");
test("false.nand_not(true)", false.nand_not(true).str, "true");
test("true.nand_not(false)", true.nand_not(false).str, "false");
test("true.nand_not(true)", true.nand_not(true).str, "true");
test("false.or_not(false)", false.or_not(false).str, "true");
test("false.or_not(true)", false.or_not(true).str, "false");
test("true.or_not(false)", true.or_not(false).str, "true");
test("true.or_not(true)", true.or_not(true).str, "true");
test("true.str", true.str, "true");
test("false.str", false.str, "false");
finish end;
end;
-------------------------------------------------------------------