Re: checking if a list is empty

2011-05-22 Thread Ian
On 12/05/2011 04:51, Chris Angelico wrote: On Thu, May 12, 2011 at 7:02 AM, Ianhobso...@gmail.com wrote: In the real world lists of zero items do not exist. You don't go shopping with a shopping list of zero items. Actually, yes you do. You maintain your shopping list between trips; whenever

Re: checking if a list is empty

2011-05-22 Thread Thomas Rachel
Am 11.05.2011 23:02 schrieb Ian: On 11/05/2011 20:13, Hans Georg Schaathun wrote: Lists do not have truth values in the application domain, and therefore truth values in the implementation domain is complicated. Exactly. Its just a convention. If it exists, its true, if if doesn't its

Re: checking if a list is empty

2011-05-21 Thread John J Lee
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Hans Georg Schaathun wrote: 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. 0 does have some special properties, though, such as being the additive

Re: checking if a list is empty

2011-05-21 Thread Emile van Sebille
On 5/21/2011 7:46 AM John J Lee said... Gregory Ewinggreg.ew...@canterbury.ac.nz writes: Hans Georg Schaathun wrote: 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. 0 does have some special properties,

Re: checking if a list is empty

2011-05-21 Thread Terry Reedy
On 5/21/2011 10:46 AM, John J Lee wrote: In the absence of an explicit interface declaration (have any standards emerged for that in Python 3, BTW?), the use of len() does give you some information about the interface, which sometimes makes it easier to change the function. I'm sure you fully

Re: checking if a list is empty

2011-05-21 Thread Steven D'Aprano
On Sat, 21 May 2011 15:46:01 +0100, John J Lee wrote: In the absence of an explicit interface declaration (have any standards emerged for that in Python 3, BTW?), the use of len() does give you some information about the interface, which sometimes makes it easier to change the function. Er,

Re: checking if a list is empty

2011-05-21 Thread Chris Angelico
On Sun, May 22, 2011 at 11:02 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 21 May 2011 15:46:01 +0100, John J Lee wrote: Er, yes? But in any realistic example (your trivial function xyzzyx below is not very realistic) you'll almost certainly get additional hints in

Re: checking if a list is empty

2011-05-21 Thread rusi
On May 22, 1:11 am, Terry Reedy tjre...@udel.edu wrote: I agree that the domain of a function should be defined from the start (and only expanded in the future). I dont understand... I dont always write correct code -- otherwise called 'a bug' -- though I never let the damn bug lose

Re: checking if a list is empty

2011-05-21 Thread Chris Angelico
On Sun, May 22, 2011 at 1:02 PM, rusi rustompm...@gmail.com wrote: Why is the C library in linux called libc6 and not just libc? I assume you mean this? http://www.linux-m68k.org/faq/glibcinfo.html When you dynamically link against a shared object, you save on executable size, but you have to

Re: checking if a list is empty

2011-05-21 Thread rusi
On May 22, 8:52 am, Chris Angelico ros...@gmail.com wrote: On Sun, May 22, 2011 at 1:02 PM, rusi rustompm...@gmail.com wrote: Why is the C library in linux called libc6 and not just libc? I assume you mean this?http://www.linux-m68k.org/faq/glibcinfo.html Ha Ha! Thanks for that link! I

Re: checking if a list is empty

2011-05-21 Thread Chris Angelico
On Sun, May 22, 2011 at 2:32 PM, rusi rustompm...@gmail.com wrote: Recently on the emacs list there was a big flame-fest because the behavior (aka interface) of return/newline changed. The argument for change: Can we have emacs behave a little more like a 21st century application? Against:

Re: checking if a list is empty

2011-05-16 Thread rusi
On May 16, 2:36 am, Terry Reedy tjre...@udel.edu wrote: On 5/15/2011 1:33 PM, rusi wrote: On May 15, 10:07 am, Steven D'Apranosteve +comp.lang.pyt...@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

Re: checking if a list is empty

2011-05-15 Thread rusi
On May 15, 10:07 am, Steven D'Aprano steve +comp.lang.pyt...@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? Dijkstra's writings I alluded to, take a logic/math line to

Re: checking if a list is empty

2011-05-15 Thread Terry Reedy
On 5/15/2011 1:33 PM, rusi wrote: On May 15, 10:07 am, Steven D'Apranosteve +comp.lang.pyt...@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

Re: checking if a list is empty

2011-05-15 Thread Steven D'Aprano
On Sun, 15 May 2011 10:33:38 -0700, rusi wrote: On May 15, 10:07 am, Steven D'Aprano steve +comp.lang.pyt...@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? [snip] I'm

Re: checking if a list is empty

2011-05-15 Thread harrismh777
rusi wrote: But on further examination (with Leibniz law above) Dijkstra's 23 = True will work consistently in all contexts but [1,2,3] = True will work sometimes and fail sometimes. It would have to be written 23 == True; [1,2,3] == True; otherwise, ... +1 QOTW --

Re: checking if a list is empty

2011-05-15 Thread Terry Reedy
On 5/15/2011 5:36 PM, Terry Reedy wrote: On 5/15/2011 1:33 PM, rusi wrote: Dijkstra's writings I alluded to, at http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html Acquiring that familiarity requires what in these financial times is known as intellectual investment; you

Re: checking if a list is empty

2011-05-15 Thread harrismh777
Steven D'Aprano wrote: I'm afraid I don't understand what you mean. Can you explain please, http://www.informatik.uni-bremen.de/agbkb/lehre/ws06-07/casl/slides/Datatypes-II.pdf Geeze, I wonder if software is mathematics kind regards, m harris --

Re: checking if a list is empty

2011-05-15 Thread Algis Kabaila
On Friday 13 May 2011 18:47:50 Hans Georg Schaathun wrote: On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico ros...@gmail.com wrote: : Writing a program requires expertise both in programming snip... And the main difference here, is that the civil engineers have a much better language

Re: checking if a list is empty

2011-05-15 Thread rusi
I have been scolded off-list for pursuing a discussion that has nothing to do with python. So I continue a bit gingerly :-) and will stop when others feel this is useless/irrelevant/whatever. Steven wrote: I'm afraid I didn't find your discussion about reification, Platonism and linguistics

Re: checking if a list is empty

2011-05-14 Thread Ian Kelly
On Fri, May 13, 2011 at 10:47 PM, harrismh777 harrismh...@charter.net wrote: http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ http://www.cs.ou.edu/~rlpage/fpclassSpring97/ There are lots of these...   the two above afaik are still doing this at the entry level...    ... supposedly, these

Re: checking if a list is empty

2011-05-14 Thread Steven D'Aprano
On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: Mathematics has existed for millenia. Hindu-arabic numerals (base-10 numbers) have been known for about one millennium The boolean domain is only a 100 years old. Unsurprisingly it is not quite 'first-class' yet: See

Re: checking if a list is empty

2011-05-14 Thread rusi
On May 14, 12:39 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: Mathematics has existed for millenia. Hindu-arabic numerals (base-10 numbers) have been known for about one millennium The boolean domain is only a 100 years

Re: checking if a list is empty

2011-05-14 Thread Hans Mulder
On 07/05/2011 02:43, Jon Clements wrote: On May 7, 12:51 am, Ian Kellyian.g.ke...@gmail.com wrote: On Fri, May 6, 2011 at 4:21 PM, Philip Semanchukphi...@semanchuk.com wrote: What if it's not a list but a tuple or a numpy array? Often I just want to iterate through an element's items and I

Re: checking if a list is empty

2011-05-14 Thread Chris Angelico
On Sat, May 14, 2011 at 5:45 PM, rusi rustompm...@gmail.com wrote: And then we get the interesting result that (True = True) is False How does this work? In Python, the = sign is illegal there, and if you mean True == True, then it's True (obviously), which is not False. Chris Angelico --

Re: checking if a list is empty

2011-05-14 Thread David Robinow
On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: rusi wrote: Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of having a non-first-class boolean type, hinders scientific/mathematical thinking/progress. Python doesn't

Re: checking if a list is empty

2011-05-14 Thread Roy Smith
In article mailman.1549.1305383294.9059.python-l...@python.org, David Robinow drobi...@gmail.com wrote: On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: rusi wrote: Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of

Re: checking if a list is empty

2011-05-14 Thread rusi
On May 14, 6:42 pm, Chris Angelico ros...@gmail.com wrote: On Sat, May 14, 2011 at 5:45 PM, rusi rustompm...@gmail.com wrote: And then we get the interesting result that (True = True) is False How does this work? In Python, the = sign is illegal there, and if you mean True == True, then

Re: checking if a list is empty

2011-05-14 Thread Chris Angelico
On Sun, May 15, 2011 at 1:47 AM, rusi rustompm...@gmail.com wrote: So since [1,2,3] is one way of writing True (lets call it True3) and [1,2] is another (call it True2) then we have True3 == True2 is False But since according to Steven (according to Python?) True3 *is the same* as True2 we

Re: checking if a list is empty

2011-05-14 Thread rusi
On May 14, 8:55 pm, Chris Angelico ros...@gmail.com wrote: On Sun, May 15, 2011 at 1:47 AM, rusi rustompm...@gmail.com wrote: So since [1,2,3] is one way of writing True (lets call it True3) and [1,2] is another (call it True2) then we have True3 == True2 is False But since according

Re: checking if a list is empty

2011-05-14 Thread Terry Reedy
On 5/14/2011 3:39 AM, Steven D'Aprano wrote: Th money-quote as regards using arbitrary objects in truth tests: [quote] All this changed with the introduction of the two-element boolean domain {true, false} which provides the vocabulary needed to assign values to boolean

Re: checking if a list is empty

2011-05-14 Thread Terry Reedy
On 5/14/2011 3:45 AM, rusi wrote: (True = True) is False is a syntax error ;-) and 'True = True' is a (useless) statement, and statements do not have boolean values, and 'True == True' *is* True, which is to say, ((True == True) is False) is False. -- Terry Jan Reedy --

Re: checking if a list is empty

2011-05-14 Thread Terry Reedy
On 5/14/2011 1:43 PM, rusi wrote: But it seems you did not get the moral? Spelt out: Beware of lossy compression! [Which is also the moral of my 'proof'] I get it now. As I suggested in response to Stephen, [] and [1] spell False and True only in boolean contexts (if/while headers) where

Re: checking if a list is empty

2011-05-14 Thread Ben Finney
rusi rustompm...@gmail.com writes: [Steven quote] In Python, [1, 2, 3] is another way of writing true, and [] is another way of writing false. Similarly with any other arbitrary objects. The only things that bools True and False are good for are: snipped [end Steven quote]

Re: checking if a list is empty

2011-05-14 Thread rusi
On May 15, 4:26 am, Ben Finney ben+pyt...@benfinney.id.au wrote: rusi rustompm...@gmail.com writes: [Steven quote] In Python, [1, 2, 3] is another way of writing true, and [] is another way of writing false. Similarly with any other arbitrary objects. The only things that bools True and

Re: checking if a list is empty

2011-05-14 Thread Steven D'Aprano
On Sat, 14 May 2011 00:45:29 -0700, rusi wrote: On May 14, 12:39 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: Mathematics has existed for millenia. Hindu-arabic numerals (base-10 numbers) have been known for about one

Re: checking if a list is empty

2011-05-14 Thread Steven D'Aprano
On Sat, 14 May 2011 19:41:32 -0700, rusi wrote: The python entities: {True, False} are not an exact (isomorphic) model for the semantic boolean domain {true, false} (which is needed for example to explicate the semantics of if while etc) Which is to say the boolean type in python is not

Re: checking if a list is empty

2011-05-13 Thread rusi
Mathematics has existed for millenia. Hindu-arabic numerals (base-10 numbers) have been known for about one millennium The boolean domain is only a 100 years old. Unsurprisingly it is not quite 'first-class' yet: See http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html [Lifted

Re: checking if a list is empty

2011-05-13 Thread Chris Rebert
On Thu, May 12, 2011 at 11:46 PM, rusi rustompm...@gmail.com wrote: snip The boolean domain is only a 100 years old. Unsurprisingly it is not quite 'first-class' yet: See It is nowadays. Every halfway-mainstream language I can think of has an explicit boolean datatype. Heck, as of C99, even C

Re: checking if a list is empty

2011-05-13 Thread Hans Georg Schaathun
On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico ros...@gmail.com wrote: : Writing a program requires expertise both in programming and in the : purpose for which it's being written. Ultimately, a programmer is a : translator; without proper comprehension of the material he's :

Re: checking if a list is empty

2011-05-13 Thread rusi
On May 13, 1:02 pm, Chris Rebert c...@rebertia.com wrote: On Thu, May 12, 2011 at 11:46 PM, rusi rustompm...@gmail.com wrote: The boolean domain is only a 100 years old. Unsurprisingly it is not quite 'first-class' yet: See It is nowadays. Every halfway-mainstream language I can think of

Re: checking if a list is empty

2011-05-13 Thread harrismh777
ru...@yahoo.com wrote: http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html A later paper by the same authors... (http://www.eis.mdx.ac.uk/research/PhDArea/saeed/paper3.pdf) These papers are fascinating reading, not only for philosophy sake

Re: checking if a list is empty

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 1:41 PM, harrismh777 harrismh...@charter.net wrote: On the other hand, kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure

Re: checking if a list is empty

2011-05-13 Thread harrismh777
Ian Kelly wrote: Well, at least Haskell is probably better as an introductory language than Lisp or Scheme. But what schools actually do this? http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html These are

Re: checking if a list is empty

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 6:48 PM, harrismh777 harrismh...@charter.net wrote: Ian Kelly wrote: Well, at least Haskell is probably better as an introductory language than Lisp or Scheme.  But what schools actually do this? http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html

Re: checking if a list is empty

2011-05-13 Thread Gregory Ewing
Ian Kelly wrote: If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, I would question whether theorem-proving is the *only* thing they will ever want to do with a

Re: checking if a list is empty

2011-05-13 Thread Gregory Ewing
harrismh777 wrote: ... and I'm also lumping two other languages into this 'category'... namely, Scheme, and Erlang. Scheme isn't really a functional language, though. You can use a subset of it in a functional way, but it doesn't have the sort of built-in support for pattern matching and

Re: checking if a list is empty

2011-05-13 Thread Gregory Ewing
rusi wrote: Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of having a non-first-class boolean type, hinders scientific/mathematical thinking/progress. Python doesn't have the flaw that Dijkstra was talking about. Fortran's flaw wasn't so much the lack of

Re: checking if a list is empty

2011-05-13 Thread harrismh777
Ian Kelly wrote: Well, at least Haskell is probably better as an introductory language than Lisp or Scheme. But what schools actually do this? http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ http://www.cs.ou.edu/~rlpage/fpclassSpring97/ There are lots of these... the two above

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On 11 May 2011 21:47:27 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: : One principle of object oriented programming is to bestow the objects : with properties reflecting known properties from the domain

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On Wed, 11 May 2011 20:16:01 -0700 (PDT), alex23 wuwe...@gmail.com wrote: : Hans Georg Schaathun h...@schaathun.net wrote: : Revolutionary indeed, so why don't we exploit the revolution : and write the programs to be as accessible as possible? : : Where do you draw the line, though? I said

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On Thu, 12 May 2011 17:44:07 +1200, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: : Roy Smith wrote: : Hans Georg Schaathun h...@schaathun.net wrote: : If both are numbers, they are converted to a common type. Otherwise, : objects of different types always compare unequal Actually, I did

Re: checking if a list is empty

2011-05-12 Thread Steven D'Aprano
On Wed, 11 May 2011 22:53:45 -0500, harrismh777 wrote: alex23 wrote: through intuitive language skills. Why not? Because the vast majority of them don't seem to want to be bothered? That could very well be... but I have a hope for them. I honestly think its not because they don't want to

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain da...@druid.net wrote: : That's not programming. That's using a canned app that a programmer : wrote that takes your unstructured input and does something useful with : it. Spreadsheets are a primitive example of that. Google is a more :

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On 11 May 2011 21:42:10 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : *Potentially* different tests. Which is exactly the point. Given an : arbitrary object, the developer doesn't know what test is appropriate. : Should I write len(x) == 0 or list(x) == [] or x.next is

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 wuwe...@gmail.com wrote: : On May 12, 7:24 am, harrismh777 harrismh...@charter.net wrote: :  We need to move away from 'canned apps' to a new day where : the masses can sit down to their computer and solve new problems with it : through

Re: checking if a list is empty

2011-05-12 Thread Ben Finney
Hans Georg Schaathun h...@schaathun.net writes: On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 wuwe...@gmail.com wrote: : On May 12, 7:24 am, harrismh777 harrismh...@charter.net wrote: :  We need to move away from 'canned apps' to a new day where : the masses can sit down to their

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On Thu, 12 May 2011 16:46:38 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: : Hans Georg Schaathun h...@schaathun.net writes: : : On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 :wuwe...@gmail.com wrote: : : On May 12, 7:24 am, harrismh777 harrismh...@charter.net wrote: : :  We

Re: checking if a list is empty

2011-05-12 Thread Ben Finney
Hans Georg Schaathun h...@schaathun.net writes: On Thu, 12 May 2011 16:46:38 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: : Hans Georg Schaathun h...@schaathun.net writes: : : On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 :wuwe...@gmail.com wrote: : : On May 12, 7:24 

Re: checking if a list is empty

2011-05-12 Thread Roy Smith
In article 931adaf9g...@mid.individual.net, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Roy Smith wrote: If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal That's just the default treatment for unrelated types that

Re: checking if a list is empty

2011-05-12 Thread Chris Angelico
On Thu, May 12, 2011 at 4:21 PM, Hans Georg Schaathun h...@schaathun.net wrote: On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain  da...@druid.net wrote: :  That's not programming.  That's using a canned app that a programmer :  wrote that takes your unstructured input and does something

Re: checking if a list is empty

2011-05-12 Thread Hans Georg Schaathun
On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico ros...@gmail.com wrote: : Anyone can join. Not everyone wants to join. Me, I'm happy here as a : priest of the software industry, and I have no desire to become a : priest of, say, automotive engineering or concrete pouring. Would an :

Re: checking if a list is empty

2011-05-12 Thread Chris Angelico
On Thu, May 12, 2011 at 10:43 PM, Hans Georg Schaathun h...@schaathun.net wrote: On Thu, 12 May 2011 22:16:10 +1000, Chris Angelico  ros...@gmail.com wrote: :  Anyone can join. Not everyone wants to join. Me, I'm happy here as a :  priest of the software industry, and I have no desire to

Re: checking if a list is empty

2011-05-12 Thread Ethan Furman
Chris Angelico wrote: On Thu, May 12, 2011 at 7:02 AM, Ian hobso...@gmail.com wrote: In the real world lists of zero items do not exist. You don't go shopping with a shopping list of zero items. Actually, yes you do. You maintain your shopping list between trips; whenever you need something,

Re: checking if a list is empty

2011-05-12 Thread Chris Angelico
On Fri, May 13, 2011 at 12:02 AM, Ethan Furman et...@stoneleaf.us wrote: Chris Angelico wrote: On Thu, May 12, 2011 at 7:02 AM, Ian hobso...@gmail.com wrote: In the real world  lists of zero items do not exist. You don't go shopping with a shopping list of zero items. Actually, yes you do.

Re: checking if a list is empty

2011-05-12 Thread ru...@yahoo.com
On 05/12/2011 12:13 AM, Steven D'Aprano wrote: [snip] http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html Shorter version: it seems that programming aptitude is a bimodal distribution, with very little migration from the can't program hump

Re: checking if a list is empty

2011-05-12 Thread Terry Reedy
On 5/11/2011 8:26 AM, Roy Smith wrote: I conclude that li == [] should have returned False. Either I'm not understanding things correctly, or this is a bug. The doc is wrong (and not only on this). I am working on a report with suggested fixes. Will post number when finish. -- Terry Jan

Re: checking if a list is empty

2011-05-12 Thread Terry Reedy
On 5/12/2011 3:37 PM, Terry Reedy wrote: On 5/11/2011 8:26 AM, Roy Smith wrote: I conclude that li == [] should have returned False. Either I'm not understanding things correctly, or this is a bug. The doc is wrong (and not only on this). I am working on a report with suggested fixes. Will

Re: checking if a list is empty

2011-05-12 Thread Steven D'Aprano
On Thu, 12 May 2011 07:36:27 -0400, Roy Smith wrote: In article 931adaf9g...@mid.individual.net, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Roy Smith wrote: If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 07 May 2011 02:51:50 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : On Fri, 06 May 2011 14:57:21 -0700, scattered wrote: : : is there any problem with : : (3) if li == []: : : ? : : Seems to work when I test it and seems to clearly test what you are : trying

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 07 May 2011 02:49:53 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : On Fri, 06 May 2011 16:05:09 -0400, Adam Tauno Williams wrote: : : I'd never accept code like if not x as an empty test. : : So much the worse for you then. : : The point of the if x idiom is that

Re: checking if a list is empty

2011-05-11 Thread Laurent Claessens
In this case, the interpretation of an arbitrary object as a boolean is peculiar for python. An empty list is a real, existing object, and the supposition that [] be false is counter-intuitive. It can be learnt, and the shorthand may be powerful when it is, but it will confuse many readers.

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman et...@stoneleaf.us wrote: : If you're going to use a language, and use it well, you have to learn : how that language works. And if the world evolves around the compiler and you, that advice suffices. However, programming is often as much

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 11:48:16 +0200, Laurent Claessens wrote: Once I wrote something like: def f(x=None): if x: print x else: print I have no value The caller of that function was something like f(cos(2*theta)) where theta come from some computations. Well.

Re: checking if a list is empty

2011-05-11 Thread Laurent Claessens
I believe you are grossly oversimplifying whatever code you had. Using the definition of f from above: theta = math.pi/4 f(math.cos(2*theta)) 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on In particular, I was using Sage; the

Re: checking if a list is empty

2011-05-11 Thread Laurent Claessens
I believe you are grossly oversimplifying whatever code you had. Using the definition of f from above: theta = math.pi/4 f(math.cos(2*theta)) 6.12303176911e-17 Yes: its oversimplifued. The angle come from a normal vector of a curve and so on In particular, I was using Sage; the

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 10:02:42 +0100, Hans Georg Schaathun wrote: The problem with 'if x' is that it requires a much more detailed understanding of python. Much more detailed? Hardly. Understanding that Python accepts any and all objects in truth-testing concepts, and the rules thereof, is

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 10:14:38 +0100, Hans Georg Schaathun wrote: In this case, the interpretation of an arbitrary object as a boolean is peculiar for python. Incorrect. It is widespread among many languages. Programmers have been writing conditional tests using arbitrary values since 1958

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 11:47:42 +0100, Hans Georg Schaathun wrote: On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman et...@stoneleaf.us wrote: : If you're going to use a language, and use it well, you have to learn : how that language works. And if the world evolves around the compiler and

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 13:36:02 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : In this case, the interpretation of an arbitrary object as a boolean is : peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 12:14:46 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : Not knowing that you can write if x instead of if x == [] is like not : knowing that you can write : : elif condition : : instead of : : else: : if condition My concern was

Re: checking if a list is empty

2011-05-11 Thread D'Arcy J.M. Cain
On Wed, 11 May 2011 11:47:42 +0100 Hans Georg Schaathun h...@schaathun.net wrote: However, programming is often as much about developing ideas in a large and complex community, where perfect universal mastery of one language is not an option, because half the community do not normally use that

Re: checking if a list is empty

2011-05-11 Thread D'Arcy J.M. Cain
On Wed, 11 May 2011 15:05:45 +0100 Hans Georg Schaathun h...@schaathun.net wrote: What could elif mean other than else: if? If run by an elf? Who knows. You do, of course, if you have learned the basics of the language you are using. if x could, for instance, mean if x is defined. It could

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 13:45:52 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : Do you think that we should avoid chained comparisons, class methods, : closures, co-routines, decorators, default values to functions, : delegation, doc tests, exceptions, factory functions,

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 12:00 AM, Hans Georg Schaathun h...@schaathun.net wrote: The fact that you need to list language by language which objects evaluate as false or equivalent to false illustrates that this has to be learnt language by language. Allowing arbitrary objects is one thing,

Re: checking if a list is empty

2011-05-11 Thread Redcat
On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: Non-programmers should be able to program? Wasn't that sort of the premise behind Visual Basic? I don't know if that was the intention, but it sure was the result in a lot of cases. --

Re: checking if a list is empty

2011-05-11 Thread Ethan Furman
Hans Georg Schaathun wrote: On 11 May 2011 13:36:02 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : In this case, the interpretation of an arbitrary object as a boolean is : peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: My concern was with the reader and not the writer. What could elif mean other than else: if? It could mean Oh, the author has made a stupid typo, I better fix it. It could mean What does the elif command do? The first time I

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 1:50 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: My concern was with the reader and not the writer. What could elif mean other than else: if? The first time I read Python code, I had

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 15:34:28 +0100, Hans Georg Schaathun wrote: On 11 May 2011 13:45:52 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : Do you think that we should avoid chained comparisons, class methods, : closures, co-routines, decorators, default values to

Re: checking if a list is empty

2011-05-11 Thread Ian Kelly
On Wed, May 11, 2011 at 8:34 AM, Hans Georg Schaathun h...@schaathun.net wrote: E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, or whereever will understand python list comprehension immediately. They would understand the underlying concept. But would somebody who

Re: checking if a list is empty

2011-05-11 Thread Eric Snow
All of this just boils down to Python providing an implicit bool cast in syntactic situations that expect conditional expressions, including if [1]. So if x: is equivalent to if bool(x). Perhaps that is the part that is not immediately obvious, being implicit to Python conditional syntax.

RE: checking if a list is empty

2011-05-11 Thread Prasad, Ramit
I don't mean to insult anyone, but I've heard and read all the arguments against Python's truth-testing, and they don't impress me in the slightest. Most of them strike me as silly. The only argument that carries any weight to me is one which I haven't seen anyone raise: if x: turns something

RE: checking if a list is empty

2011-05-11 Thread Prasad, Ramit
The audience I am concerned about is the ones who are over-educated into using and having used a score of different meanings of the same symbols. They will be used to their intuition being wrong when they move into a new context. Being explicit will help them. I find this argument to be

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain da...@druid.net wrote: : Non-programmers should be able to program? That was not really what I suggested; I was primarily talking about reading programs and commenting on formulæ and algorithms. : Should non-doctors be able to doctor? If

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 16:26:40 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: : 1. My concern was not about clueless newbies. They need to :learn. My concern is about experienced scientists and engineers who :are simply new to python. : : Which makes them clueless newbies

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Thu, 12 May 2011 02:05:21 +1000, Chris Angelico ros...@gmail.com wrote: : In a Bourne shell script, if ends with fi... case ends with esac... so : file would end with... hmm. Yeah, I think it's best to know the : language you're trying to comprehend, and/or actually look at context :

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 10:27:49 -0400, D'Arcy J.M. Cain da...@druid.net wrote: : When did we come to the idea that people should be able to program in a : language without actually learning it? The fact that Python comes so : close to that possibility is nothing short of revolutionary.

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 10:31:59 -0600, Ian Kelly ian.g.ke...@gmail.com wrote: : (x + 3 for x in xs if x % 2 == 1) Interesting. Thanks. That might come in handy some time. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit ramit.pra...@jpmchase.com wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than

  1   2   >