[Python-ideas] the optional "as" statement inside "if" statements
Matt Joiner
anacrolix at gmail.com
Sat Jul 7 18:03:15 CEST 2012
Sorry yes I meant block scoping. I assimilated terms from further up
in the thread I think.
I mean that there can be no temporary/block/localized scope for a name
to within the if statement, so there's no reason not to put it on the
line above. FWIW I've grown fond of function level scoping, it really
reduces confusion in closures and encourages smaller functions to
avoid name leaks.
Go has something like the OP asks for:
if x := SomeFunc(); x > 3 {
// x scoped only within this block
}
Haskell also lets you name expressions like:
someFunc y at x:xs = ...
But in Python I still think this is best:
x = some_func()
if x > 3:
# no scoping :)
On Thu, Jul 5, 2012 at 1:30 AM, Masklinn <masklinn at masklinn.net> wrote:
> On 2012-07-04, at 18:35 , Devin Jeanpierre wrote:
>
>> On Wed, Jul 4, 2012 at 12:19 PM, Matt Joiner <anacrolix at gmail.com> wrote:
>>> There's no point doing this in Python since scoping is function-level
>>> and not lexical. Just move the assignment to the line preceding the if
>>> statement.
>>
>> I'm not sure what distinction you want to draw here between "lexical
>> scoping" and "function-level scoping". Is your issue that scopes
>> cannot be inferred during the lexing phase? Or is it something else?
>
> Guessing he misused "lexical scoping" for block-based scoping (as in
> e.g. C) or explicit scoping constructs (e.g. `let`-type constructs).
>
>> Generally, AIUI, because lexical scoping is only really interesting in
>> contrast to static scoping
>
> And I see you miswrite as well, "lexical scoping" and "static scoping"
> are the same thing, and opposed to "dynamic scoping" (where name
> resolution traverses the call stack).
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
More information about the Python-ideas
mailing list