pre-PEP: Suite-Based Keywords

Bengt Richter bokr at oz.net
Sat Apr 16 22:24:12 EDT 2005


On Sat, 16 Apr 2005 13:58:38 -0700, Brian Sabbey <sabbey at u.washington.edu> wrote:

[...]
>
>Yes, my description of the syntax was ambiguous.  To clarify, I intended 
>the syntax to be backwardly compatible.  That is, one would not be able to 
>use a suite to define keywords if there already exists a suite for other 
>reasons.  So, one would not be able to use a suite to pass keywords to 'f' 
>in this situation:
>
>if f():
>      x = 1
>
>This code should behave exactly as it does now.
>
>I agree that the ellipsis idea probably makes the code more readable, and 
>it may be a good idea to have them for that reason.  However, ellipses are 
>not necessary as a way to disambiguate the syntax; all statements 
>containing suites currently begin with a keyword, and keyword suites would 
>not.
>
Using my expression where: trailer, the above if could be spelled

    if f(x) where: x=1: # where:<suite> acts like '' other than its semantics.
       do_something()

I was debating whether to use a where: that applied to a whole previous statement and its suite,
indenting as if the where were a following statment, e.g.,

    if f(x):
        do_something()
    where:
        x = 1

But I thought that could get too far away, and not cover many use cases that could be done
other ways. The thing that where does though is create a transient namespace for the suite
bindings, so they don't clobber the calling namespace the way just prefixing a setup would

    x = 1 # clobber x
    if f(x):
        do_something()

Shoot, I just has another idea about the ::<suite> expression -- instead of returning a tuple,
it could return an order-maintaining subtype of dict with methods for items(), keys() and values()
and that would make better spellings for many examples in Kay's post ;-/

Also suite-based keyword calling would just become

    f(10, 4, **::  # note ease of including other parameters if part of the signature
         x = 1
         y = 2 )

and you could do
    print (::
        x = 1
        y = 2
    ).keys()
    => ['x', 'y']

or call foo
    foo(self, whatever, *(::
        x = 1
        y = 2).values())

Oh well, that's the way ideas evolve ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list