Re: request for change of boolean
Kat wrote:
> > Kat wrote:
> > >
> > >
> > > Is it possible to change how boolean expressions are evaluated such that
> > > only
> > > values greater than 0 pass this test? :
Yes it is, but this would be a bad idea because it would break a lot of code,
and it is not the way that programming languages have been traditionally
implemented. Not that I have a problem per se about breaking away from
traditions, but it is important to "surprise" people only when it is demonstrably
better than the traditional way.
I have not come across any programming language (that doesn't have a native
boolean type) that treats a non-zero value as false. Traditionally, zero is
falsehood and (not zero) is truth. There are some languages that use specific
integers to mean truth, for example Forth uses -1 (if all bits off means false
then all bits on means true).
In languages that support the syntax ...
if (value) then
where 'value' is a numeric data type, you will find that this typically is
shorthand syntax for ...
if (value != 0) then ...
This can be seen when you look at the generated object code.
When dealing with languages that have a built-in boolean type, such as Pascal,
such variables do not have sematic numeric values. Instead they have built-in
literals of True and False. Typically boolean datatypes are not numeric
datatypes, in that they do not allow arithetic, or comparsion outside of the
boolean type.
X : Boolean;
Y : Integer;
if (X = Y) ***** Syntax error
X + Y **** Syntax error.
> I liked the way bool and bytebool worked and evaluated in Pascal. Rather like
> common sense, or a checkbook. If the value was positive, any value, then it
> was there, money was in the checkbook, it was TRUE. If it was negative or
> zero,
> it was not there, there was no money, and it evaluated to FALSE.
Please show me the Pascal code that demonstrates this because I don't think you
are remembering correctly.
And by the way, my primary job involves developing financial software for banks
etc... and a negative balance does not mean there is 'no money'. It means that
the customer owes the institution some money and we calculate interest on that
balance.
> Somehow, it
> makes sense to me that Eu would have extended that to sequences (so
> {0,0,0,-300}
> = false, while {0,0,5000,0} is true).
It would be good to have a native boolean type, in the same way as any datatype
helps with bug detection, but that would detract from the freedom that Euphoria
offers. I am willing to offset the benefits of static datatype checking against
the flexibility and simplicity of Euphoria. The 'type' system in Euphoria is
optional and I supposed could do with a few enhancements, but I can live with it
for now.
> In reality, it seems to be not only flamebait
> on my butt,
I hope you didn't think I was flaming you, because that is very not true. You
know me better than that, Kat.
> but a great example of why it's a good idea to NOT provide specific
> code to illustrate a point.
I disagree because by showing a specific example gave us some insight in to the
way you are thinking, and that can't be a bad thing. However, in this specific
example, it also showed us that you had a misunderstanding of the way that the
open() function works. It does not return a boolean and thus your argument was
weakened. It returns EITHER a valid file handle (a positive integer) OR an error
flag (-1).
--
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell
|
Not Categorized, Please Help
|
|