checking if a list is empty

Terry Reedy tjreedy at udel.edu
Sun May 15 17:36:01 EDT 2011


On 5/15/2011 1:33 PM, rusi wrote:
> On May 15, 10:07 am, Steven D'Aprano<steve
> +comp.lang.pyt... at pearwood.info>  wrote:
>>
>> I'm afraid I don't understand what you mean. Can you explain please, what
>> properties of "first class booleans" do you think are missing from Python?

Given the usual CS definition of 'first class object', all Python 
objects are first class. But that does not preclude other definitions.

> Dijkstra's writings I alluded to, take a logic/math line to this.  Let
> me try to rephrase Dijkstra (who is now sadly not able to defend our
> (mis)understandings of his writings) in a more linguistic way:
>
> In English when we say something like "x is y"  the y (predicate) can
> be an adjective phrase -- the apple is red -- or a noun phrase -- the
> apple is a fruit.
>
> They seem similar; they are very different -- you agree??

Sometimes. Sometimes it could mean 'the apple is fruity' or 'the apple 
has the characters that define the wider grouping of fruits'. "John is 
brilliant", "John is a brilliant man", and "John is a genius" (there is 
no 'a brilliant') pretty much have the same effective meaning. But I get 
the point about reification.

>> From times immemorial 'true' and 'false' have been used in the
> adjective sense: eg Such-and-such statement is true.
> Boole's contribution -- actually Dijkstra's recognition of Boole's
> contribution -- is that dignifying {true, false} from adjectives to
> nouns -- the boolean domain -- fundamentally alter and improve the
> rules and possibilities for our thinking. [See his puzzles in the same
> paper:
> http://www.google.com/url?sa=D&q=http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html
>
> As an analogy for this consider arithmetic.
>
> Even primitive people can count: My 3 children, my 5 sheep.  They do
> this with the ordinals -- first child, second child, third child...
> But arithmetic cannot really take off until we allow these numbers
> (ordinals) to be dignified into entities in their own right --
> cardinals.
> ie the mathematician needs to believe in the existence of the numbers
> 1,2 etc for him to do his job well.
>
> [As an aside I may mention that philosophers of mathematicians will
> call this platonism: "In which heaven do these numbers exist?"
> And platonism is mysticism. And mysticism is bullshit.  But the vast
> majority of practicing mathematicians refuse to be dislodged from
> their 'platonic heaven.'  For them mathematics can only be done if it
> is done in 'discovery' mode and not in 'invention' mode.]
>
> And so just as good math happens by believing that the numbers exist
> and discovering their properties, good logic happens when we believe
> that {True, False} exist (in some platonic heaven). Which is to say
> they should be nouns in our language.
>
> Well that in summary is the Boole's ideology (Dijkstra's evangelism)
> understood linguistically and independent of python/programming.
>
> Reapplied back to the math/programming field, we find that if a value-
> domain (data-type) has to be first-class, it at the least has to be a
> denotable entity in the language which should be conformable with its
> abstract/expected properties.
> For example if my language seems to have entities like '2' '3' '+' but
> 2+3 does not work out equal to 5 we would (I hope!) not say the
> language has first-class numbers.

You seem to equate 'number' with 'natural number' in the classical 
sense. If '2' and '3' are residue classes (remainers) mod 5, then 2 + 3 
is 0. Even kids understand clock arithmetics. Of course,
the 24 hour (0 to 23 hourse) is saner than the older 1-12,am/pm system,
but kids even manage with that.

> But in order for any of this discussion to be possible, equality
> should be well-defined.
> Which means that in addition to being an equivalence relation it must
> have substitutivity
> http://en.wikipedia.org/wiki/Equality_%28mathematics%29#Some_basic_logical_properties_of_equality
> which is another form of a very fundamental principle attributed to
> Leibniz, the principle of identity of indiscernibles:
> http://en.wikipedia.org/wiki/Leibniz%27s_law
>
> Seemingly you and Dijkstra are saying something similar when you say
> [1,2,3] is a way of writing true
> and he says 2<3 is a way of writing true.
> But on further examination (with Leibniz law above) Dijkstra's 2<3 =
> True will work consistently in all contexts

In general, a < b will work consistently as generally expected of total 
orders if, but only if, a and b are members of a totally ordered set and 
< indicates that total order. If '<' represents a partial order, 'a<b' 
may be undefined or defined as false when 'b<a' is also false.

 > but [1,2,3] = True will work sometimes and fail sometimes.

'Bool(<normal expression*>) is a much a spelling of true or false as 'a 
< b'. It works just as consistently in all contexts.

*nornal expression: evaluates to an object with a well-defined boolean 
value, which is to say, causes bool() to return True or False.

> In mathSpeak we say, the definition of bool is not well defined

The math definition of bool or the Python definition?
And what definition of 'well-defined'? On builtins, bool(ob) always 
returns the same value. And the values are pretty consistent.

> In CSSpeak we say the definition is not first class.

What CS definition?

-- 
Terry Jan Reedy




More information about the Python-list mailing list