Re: ESL Master Include File

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> Derek Parnell wrote:
> 
> > Pete Lomax wrote:
> >
> > [snip]
> >> Despite the highly unlikely chance
> >> of such things, some libraries actually do define TRUE=(1=1) and
> >> FALSE=(1=0).
> >
> > That would be me blink
> >
> >> There is nothing wrong with using tri-logic with say isTLtrue=1,
> >> isTLunknown=0, and isTLfalse=-1, (though isTLfalse=0, and
> >> isTLunknown=-1 would probably be just as effective) but
> >> defining FALSE as -1 is just brain-dead stupidity.
> >
> > Why? The only requirement is that TRUE and FALSE have different values
> > from each other. One could have ...
> >
> > constant  TRUE  = 't',
> >           FALSE = 'f'
> >
> > And all code that relied on using TRUE and FALSE would still work.
> > One's code should never be doing arithetic on boolean values and never
> > doing relative comparisions either (less than, greater than). Instead
> > one's code should only be doing assignments and equality tests.
> 
> What about boolean operations such as 'not'?

LOL...Thanks Juergen, I forgot about the obvious ones : not, and, or, xor.

> }}}
<eucode>
> constant
>    FALSE = 0,
>    TRUE = 1
> 
> ? TRUE = not FALSE  -- prints 1 (which equals TRUE here) -> correct
> <font color="#330033"></eucode>
{{{
</font>

This is because 'not' is built into Euphoria and it assumes that FALSE is zero
and TRUE is 1. If we could define a replacement functions, they would go
something like ...

  function not(boolean A)
      if A = TRUE then
         return FALSE
      else
         return TRUE
      end if
  end function

  function and(boolean A, boolean B)
      if A = TRUE and B = TRUE then
         return TRUE
      else
         return FALSE
      end if
  end function

  function or(boolean A, boolean B)
      if A = TRUE or B = TRUE then
         return TRUE
      end if 
      return FALSE
  end function

  function xor(boolean A, boolean B)
      if A = B then
         return FALSE
      end if
      return TRUE
  end function

Of course, this is grossly inefficient but that's just an implementation detail,
the principle theory still applies.

> 
> > BTW, and I'm sure you already know this, but there are plenty of
> > languages that implement TRUE as -1 instead of 1.
> 
> Then hopefully the boolean operators in these languages work
> consistently, so that always
>    not FALSE = TRUE
>    not TRUE = FALSE
>    FALSE xor TRUE = TRUE
>    etc.

Of course. They also have built-in 'not', 'and', 'or' and 'xor' boolean
operations.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu