Re: atom() ambiguity
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Jun 22, 1998
- 654 views
On Fri, 19 Jun 1998, Daniel Berstein wrote: > constant true=1 > constant false=0 > > or type: > > type boolean (integer x) > if x then -- If 'x' is != 0 > return 1 > else > return 0 -- If x = 0 > end type This code won't work. A program would crash if it a boolean was set to false(0) and wouldn't crash if x = 7 (for instance). After thinking a lot recently, this is the best solution (IMHO): constant TypeFail = 0 constant True = 1, False = 0 type boolean(object x) if not integer(x) then return TypeFail end if return x=not(not x) end type -- Example code boolean a,b,q a = True b = False q = (a or b) and not (a and b) -- Carl R White E-mail...: cyrek- at -bigfoot.com / Remove the hyphens before Finger...: crwhite- at -dcsun1.comp.brad.ac.uk \ mailing or fingering... Url......: http://www.bigfoot.com/~cyrek/