pre-PEP: Suite-Based Keywords - syntax proposal

Bengt Richter bokr at oz.net
Sun Apr 17 22:03:22 EDT 2005


On 17 Apr 2005 09:27:34 -0700, "Kay Schluehr" <kay.schluehr at gmx.net> wrote:

>> Exactly. Except the above example is from the day-old-bread
>items-tuple-returning version of :: ;-)
>> And with an ordered dict subtype there is no need for the generator
>expression either,
>> since there is a values method for dicts (which in the subtype would
>preserve order). E.g.,
>>
>>  x = property(*seq) where:
>>              seq = (::
>>                  def get_x():
>>                      return self.__x
>>                  def set_x(value):
>>                      self.__x = value
>>                  del_x = None
>>                  doc   = "I'm the 'x' property." ).values())
>>
>> Or more directly:
>>
>>  x = property(*(::
>>                  def get_x():
>>                      return self.__x
>>                  def set_x(value):
>>                      self.__x = value
>>                  del_x = None
>>                  doc   = "I'm the 'x' property." ).values())
>
>Hmmm ... now You eliminate "where" completely in favor for '::'. This
>may be reasonable because '::' is stronger and less context dependent.
>But on the other hand it may be also reasonable to eliminate '::'
>towards a stronger "where" ;)
>
>
>x = property(**kw) where kw:
>            doc = "I'm the 'x' property."
>            def fget(self):
>                return self.__x
>
>
>x = property(*args) where args:
>            def fget(self):
>                return self.__x
>            fset = None
>            fdel = None
>            doc = "I'm the 'x' property."
>
I like this. But how would you put "where args:" and "where kw:" if you needed both?
also, is it looking back to see the '*' or '**' to do (::x=1).values vs. (::x=1)
and how about (::x=1).keys() or (::x=1).items() ? And what if you wanted to pass
(::x=1) as a dict object without ** expansion into a keyword dict?

Maybe we need asterisks on both ends. e.g.,

    foo(dct, values, *args, **kw):
       where **dct:
          x=1
       where *values:
          x=2
       where *args:
          x=3
       where **kw:
          x=4

But that still doesn't give you, e.g.,

       foo(keys) where:
           keys=sorted((::
               from interesting.module import *
           ).keys())

I like clean sugar, but I still want to be able to
get at the general primitives to compose them in ways
that can't be anticipated until a use case comes up.
And then if the primitives are inaccessible, one is
out of luck or doomed to workaround hacking ;-)

>
>Put definitions into a list:
>
>l = list(*args) where args:
>        def fget(self):
>            return self.__x
>        doc = "I'm the 'x' property."
>
>
>Nest suites:
>
>x = property(*args) where args:
>        t = tuple(*t) where t:
>            def fget(self):
>                return self.__x
>            fset = None
>            fdel = None
>            doc = "I'm the 'x' property."
>
>
>Evaluate conditions:
>
>if f(*args)==1 where args:
>   x = 1
>   y = 2
>
>I think this version is more mainstream syntax ( and without braces and
>additional punctuation ) than the unary prefix operator '::' which
>drops statements into expressions within expressions.
>
I like this mainstream syntax for ordinary use cases, but as mentioned,
I'd still like to have primitives accessible. I don't see why both
couldn't live in harmony ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list