[Python-Dev] A syntax for function attributes?

Charles Cazabon python@discworld.dyndns.org
Thu, 31 Jul 2003 09:10:49 -0600


Pat Miller <patmiller@llnl.gov> wrote:
> Michael wrote:
> > I don't object to a syntax for function attributes [...]
 
> I agree that
> 
> def sqr(x):
>     return x*x
> sqr.inline = true
> 
> is about the same length as
> 
> def sqr [inline=true](x):
>     return x*x

If it's going to look like a mapping, and quack like a mapping, why not make it
a mapping?

  def funcname(args) {attribute_mapping} :
      ...

Docstrings then just become symantic sugar for this:

  def sqr(x) {
    '__doc__' : '''Return the square of x.''',
    'inline' : True
  }:
      return x*x

Charles
-- 
-----------------------------------------------------------------------
Charles Cazabon                           <python@discworld.dyndns.org>
GPL'ed software available at:     http://www.qcc.ca/~charlesc/software/
-----------------------------------------------------------------------