Re: request for change of boolean
- Posted by Derek Parnell <ddparnell at bi?pond?com> Dec 06, 2007
- 841 views
Kat wrote: > > > Is it possible to change how boolean expressions are evaluated such that only > values greater than 0 pass this test? : Why? Is there a compelling reason to change the current implementation? For example, does it cause your programs to fail or run slower? > }}} <eucode> > readfile = open(flagfilename,"r") > if readfile then > -- it's there, process it > end if > </eucode> {{{ You should code this as ... if readfile < 0 then ... Would that be a problem? > Currently, if readfile = -1 , it evaluates to TRUE, when in fact > the readfile was not opened. The valid values that can be returned from open() are all positive integers greater than 2. The values 0, 1, and 2 are pre-opened files for stdin, stdout, and stderr. Thus negative values are returned to indicate that the file could not be opened. A positive value would actually imply that it opened just fine. Alternatively you could write a new function ...
function OpenFile(sequence name, sequence type) integer fh fh = open(name, type) if fh < 0 then rc = 0 else rc = 1 end if return {rc, fh} end function object readfile readfile = OpenFile(flagfilename,"r") if readfile[1] then -- it's there, process it end if
But I can't see that that is much of an improvement. Maybe I'm wrong though. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell