Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6699

Re: scope of function parameters (take two)

References <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <F4EAD1ED-563D-4D6E-A50C-68308A9F26B7@mcgill.ca> <BANLkTimRchgQDVoHpF=mgVX51+Ur1igtnA@mail.gmail.com> <BANLkTik69+ga_aRnYPcf+hMwTsai4V3a9w@mail.gmail.com>
Date 2011-05-31 13:34 +1000
Subject Re: scope of function parameters (take two)
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2293.1306812886.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, May 31, 2011 at 1:18 PM, Daniel Kluev <dan.kluev@gmail.com> wrote:
> On Tue, May 31, 2011 at 2:05 PM, Chris Angelico <rosuav@gmail.com> wrote:
>> Infinitely-nested scoping is simply one of the casualties of a
>> non-declarative language.
>
> Well, this is not accurate, as you can have 'infinitely-nested
> scoping' in python, in form of nested functions. For example, you can
> use map(lambda x: <expressions with x, including other
> map/filter/reduce/lambda's>, list_of_x), and you will have your
> isolated scopes. Although due to lambdas supporting only expressions,
> following this style leads to awkward and complicated code (and/or
> instead if, map instead for, and so on).

That's an incredibly messy workaround, and would get ridiculous if you
tried going many levels in. It's like saying that a C-style 'switch'
statement can be implemented in Python using a dictionary of
lambdas... and then trying to implement fall-through. But you're
right; a lambda does technically create something of a nested scope -
albeit one in which the only internal variables are its parameters.

Chris Angelico

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: scope of function parameters (take two) Chris Angelico <rosuav@gmail.com> - 2011-05-31 13:34 +1000

csiph-web