Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; '(at': 0.04; 'decorator': 0.09; 'degree,': 0.09; 'subject:number': 0.09; 'whole,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'be:': 0.16; 'declaration': 0.16; 'degree.': 0.16; 'exist.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'itertools': 0.16; 'unhashable': 0.16; 'elements': 0.16; 'wrote:': 0.18; "python's": 0.19; 'programming': 0.22; 'aug': 0.22; 'coding': 0.22; 'cc:addr:python.org': 0.22; 'adds': 0.24; 'certainly': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'source': 0.25; 'equivalent': 0.26; 'least': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'skip:@ 10': 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; '(although': 0.31; 'bunch': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'class': 0.32; 'probably': 0.32; 'style': 0.33; 'maybe': 0.34; 'subject:the': 0.34; 'agree': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'done': 0.36; 'doing': 0.36; 'useful': 0.36; 'should': 0.36; 'skip:o 20': 0.38; 'sometimes': 0.38; 'tasks': 0.38; 'pm,': 0.38; 'that,': 0.38; 'extremely': 0.39; 'functional': 0.39; 'most': 0.60; "you're": 0.61; 'name': 0.63; 'kind': 0.63; 'effectively': 0.66; 'default': 0.69; 'subject:get': 0.81; 'niche': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=QZru+VOtDUUyqwMnJ5KKzAlx0wlkUbe25b3kFbDJsQY=; b=IuZXRGhPUDLLUgZMjlJVKNUT70YOkodgBf8ooxyhiyKq63J5r+Zz4VDc2lnJGZ1BLR qvHv+r+8XFdPs4KRqFbS6MYcYYve5lpYXmW0fXSwA7xagX8uEHdjNWQc0EKfN87lQ77u WIe2X0pdahSxmx3o3OB6mpUw/keYw5W139vuu7qcpkGxYotEM6KUFDQ6Qa3VaFIvasNl 7hAN1w9K4kCj3aQsPpeZz1mDI0MZWKXvFRorjosqgOfnAfKtVHZC8rDzmNFJfJ8CBEIG DfolamgEROhmNhsvujhUPpoNN0rQGBEB3myI7DnoUdSnjvvSJ1JZD09LSUnIo5PTTqfc re0Q== MIME-Version: 1.0 X-Received: by 10.51.17.2 with SMTP id ga2mr28456815igd.2.1407751667015; Mon, 11 Aug 2014 03:07:47 -0700 (PDT) In-Reply-To: <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> References: <53E658CD.5020904@gmail.com> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <8c41d779-0c26-430a-a915-08c2b962e0e7@googlegroups.com> <53e89063$0$29890$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 11 Aug 2014 20:07:46 +1000 Subject: Re: how to get the ordinal number in list From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407751676 news.xs4all.nl 2917 [2001:888:2000:d::a6]:37702 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76041 On Mon, Aug 11, 2014 at 7:44 PM, Steven D'Aprano wrote: > I think this is why both declarative and functional programming idioms > will remain niche (although important niches). Most tasks are inherently > imperative to at least some degree, and often a *great* degree. Maybe that's true as a whole, but there are certainly ways in which certain declarative or functional elements can be extremely useful to an otherwise-imperative program. Python's (list etc) comprehensions are broadly functional in style, as are most of the itertools oddments. There's not a lot that's declarative in Python, but (at least in Python 3) the presence of __eq__() in a class disables the default __hash__ implementation, which effectively makes __eq__ a declaration "I'm doing custom equality, so I'm unhashable unless I say otherwise". I've sometimes done some extremely declarative coding in places; my MUD client builds its menus by looking for specially-named functions and getting some metadata from them to work out what the menu item name should be. An approximate Python equivalent would be: @filemenu("E_xit") def exit(): prompt("Do you really want to exit?") where the presence of the function is what causes the menu item to exist. In this case, the 'filemenu' decorator is probably imperative code that adds the menu item to the File menu, but if you're reading through a source file that has a bunch of functions like that, you'd have to agree that that's a declarative style of coding. And it's a style that works well for this kind of thing. ChrisA