Re: 'Unknown' and three-valued logic (was: Example where Euphoria ...)
- Posted by jbrown105 at speedymail.org Nov 25, 2002
- 496 views
On 0, Rom <kjehas at frisurf.no> wrote: > > From: <jbrown105 at speedymail.org> > > > but also define global funcs pEQ, pNE, pGT, pLT, pGE, and pLE, then do > > this: > > > > pAnd ( pEQ(a, False), pGT(b, 20) ) > > > I am trying like this: > > global constant TRUE = 1, FALSE = -1, NIL = 0 No this (use C false rather than BASIC false): global constant TRUE = 1, FALSE = 0, NIL = {1632324,0,45,75243343,547642} --yes NIL is a sequence, its set to a sequence unlikely to ever be used --by the program as an actual value - its a kludge, but in general --its a working kludge. (and those are the best kludges of all. ;) > > global type eboolean( integer x) > return (x = TRUE) or (x = FALSE) or (x = NIL) > end type Oops ... better do it this way: global type eboolean( object x) if sequence(x) and equal(x,NIL) then return TRUE end if if not integer(x) then return 0 end if return (x = TRUE) or (x = FALSE) end type > > global function pEQ( integer a, integer b) > if a = b then return TRUE > else return FALSE > -- it never returns NIL???? > end if > end function Gotta fix this too. First add a new "integer" type. global type einteger(object x) if sequence(x) then return equal(x, NIL) end if return integer(x) end type Might also wanna make an "eatom" type too. (Sequences should be just fine, however.) Now, on to the real function ... global function pEQ( einteger a, einteger b) if equal(a,NIL) or equal(b,NIL) then return NIL end if -- it returns NIL here, above. if a = b then return TRUE else return FALSE end if end function > Now this should work. > > eboolean decision > integer a > a = 5 > > decision = pEQ( a, 5) > > > I run into problems because a cannot test if an integer is instanciated (they > are all intanciated in Euphoria anyhow). Thats seperate from NIL type however. Its a different issue. Don't confuse the two, please. > > When I define an eboolean type .... unstanciated state is represented by > NIL..... no problem. > eboolean A > A = NIL > But I cannot put that information into an integer? Cuz I use a sequence for NIL, its really those that are tricky. Also, if a function uses a real integer, rather than an einteger (or atom rather than eatom) than you can also have troubles with type-check errors. :( > I will need a quite a new type for integer that behaves like an integer but > also has a nil flag. > Don't know how to do that... > > Thank you for your keen interest > > Regards > Rom > No problem. Hope my example helps you out. jbrown > ==^^=============================================================== > This email was sent to: jbrown105 at speedymail.org > > > --