python3: 'where' keyword

Jonas Galvez jonasgalvez at gmail.com
Mon Jan 10 08:33:48 EST 2005


Andrey Tatarinov wrote:
> It would be great to be able to reverse usage/definition parts 
> in haskell-way with "where" keyword.

Hi folks, I really like this idea. But I couldn't help but think 
of a few alternative ways. I'm no language design expert by any 
means, but I'm a little concerned with the idea of an 'expression' 
preceding a 'block'. Maybe I'm naive (actually, I'm pretty sure I 
am), but I think a decorator-like syntax would be a little more 
Pythonic. Here's a small example:

def where(closure=None, *v):
    if not False in v:
        closure(*v)

def foo(a, b):
    @where(a: int, b: int):
        return str(a) + str(b)
    raise TypeMismatch

The (variable : type) could be turned into a syntact sugar for 
(type(variable) is type). Basically, this would be a simple 
implementation of the so called "closures", where a decorator is 
able to 'receive' a code block, which would be passed as a 
function as the first argument of the decorator. (Is this clear?)

As I said, I'm no language design expert and I'm sure I'm breaking 
a few important rules here heh. But I find it cool. This is not a 
proposal. I'm just thinking out loud :)


Jonas



More information about the Python-list mailing list