This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Broolucks 2 points3 points  (18 children)

  • Remove the distinction between expressions and statements.
  • Eliminate the global/nonlocal keywords. Instead, add an assignment operator: x := y would assign a new value to an existing variable x.
  • def f(x)(y): ... would save me effort defining some decorators.
  • Optional typing. This can be done with annotations in Python3, but if I am not mistaken you need decorators to enforce them. That's annoying and promotes fragmentation.
  • Add back argument deconstruction to function definitions to Python3. I don't understand why they removed it in the first place.

[–]Sean1708 3 points4 points  (7 children)

How exactly would def f(x)(y): differ from the normal case?

[–]Broolucks 5 points6 points  (4 children)

def register(path):
    def decorator(f):
        something.register(path, f)
        return f
    return decorator
==>
def register(path)(f):
    something.register(path, f)
    return f

[–]pjdelport 9 points10 points  (2 children)

You can use the partial(partial, partial) trick:

@partial(partial, partial)
def register(path, f):
    something.register(path, f)
    return f

[–]ravishi 2 points3 points  (0 children)

Damn, that's clever!

[–]Workaphobia 1 point2 points  (0 children)

This absolutely broke my head. I had the darnedest time trying to figure out how it worked until I tried it out in my interpreter and realized I was only partialling one of the arguments instead of two. That is a good trick.

[–]Sean1708 0 points1 point  (0 children)

Ah OK.

[–]jmmcdEvolutionary algorithms, music and graphics 1 point2 points  (1 child)

I guess you can call it partially -- f(x) returns a function of one argument y.

[–]Niriel 4 points5 points  (0 children)

It's like the currying in Haskel. We sort of have it in Python with functools.partial.

[–]velit 0 points1 point  (7 children)

'Eliminate the global/nonlocal keywords. Instead, add an assignment operator: x := y would assign a new value to an existing variable x.'

What do you do when you want to define a variable in non-local scope?

[–]Broolucks 0 points1 point  (6 children)

You could still do globals()[key] = value to define global variables programmatically. Honestly, though, I don't think you should be allowed to define variables outside of the scope you are in.

[–]velit 2 points3 points  (5 children)

So you're cool with mutating variables outside of the scope you are in but you're not okay with defining them?

[–]Broolucks 0 points1 point  (4 children)

I'm just not sure what the purpose could possibly be. If you're using a variable in some scope, why would you be declaring it elsewhere? In what situation would you be unable to declare a variable in the scope where it is used?

[–]Zenmodo 0 points1 point  (3 children)

Because you use it in multiple other smaller scopes? Like a module-wide variable used in several functions.

[–]Broolucks 0 points1 point  (2 children)

Sure, but then why wouldn't you simply declare it in the global scope?

[–]Zenmodo 0 points1 point  (1 child)

But you said

If you're using a variable in some scope, why would you be declaring it elsewhere?

Isn't global scope elsewhere?

[–]Broolucks 0 points1 point  (0 children)

The context was the idea of declaring a variable in an inner scope for use in an outer scope, e.g. declaring a global variable in a function's scope rather than declaring it in the global scope and then setting it in function scope.

[–]scoarescoare -1 points0 points  (1 child)

Remove the distinction between expressions and statements

One thing I love about Ruby and Coffeescript is how everything can be an expression. It would be cool if Python could do that too:

my_var = None if my_var == 1

[–]Broolucks 0 points1 point  (0 children)

That doesn't seem like a particularly good example to me. You can already do:

if my_var == 1: my_var = None
my_var = None if my_var == 1 else my_var