[Types-sig] New syntax?

Greg Stein gstein@lyra.org
Thu, 16 Dec 1999 14:13:11 -0800 (PST)

On Thu, 16 Dec 1999, Martijn Faassen wrote:

>... example syntax for a Python syntax to declare interfaces ...

Ah. Good. That is better than your/Paul's previous suggestions.

> > Inline vs. external is a different question (and I vote for former). But
> > different syntaxes is a big problem that is easily avoided.
> So what are you suggesting if you would be voting for external, then? A
> Python based system such as the one I proposed earlier? Or is this why
> you're voting for internal?

By "for former", I meant that I want an internal syntax. Something like
Tim's suggestion. It keeps the declaration closest to the implementation,
which (IMO) is best. It is kind of like comments and code: they can easily
drift apart, especially if the two are distant from each other.

In your example above, I think it would be a bit painful to flip back and
forth between the "class" and "varclass" every time you wanted to add a

In fact, I don't even like Tim's notion of declaring a function since a
"def" is more than adequate for doing that. I would like to see something

class Foo:
  decl class a: Int "The <a> class variable is for ..."
  a = 1

  decl b: String
  "Member variable. Alternative location for a doc string"

  def bar(x: Int, y: String) -> List:
    "Doc string goes here"
    return some_list

Note that an interface definition would look exactly the same, except that
"interface" would be used instead of "class", variable assignments are not
allowed, and functions cannot have a body (only a doc string).

Note the use of "decl class ..." to define class variables, while "decl
..." is for member variables. I'm not sure if we should instead use Tim's
suggestion of "decl member ...", though. Given the position of the
declaration, I think "decl member" might actually be better because it
makes it clear that <b> is a *member* variable, despite being in a
location that is normally used for class variables. An alternative would
be a different "decl" keyword just for members.
[ I *really* don't like member declarations in the __init__() method as
  some people have shown. Those could be confused with declarations of
  local vars, which I hope we aren't going to have. ]

Consider the above example, my latest proposal for syntax changes in
support of declarations. Obviously, a bit more detail is needed for things
like parameterized types, but I think the above is representative of where
I'd like to see things go.

And I won't suggest anything for an external syntax, since I don't support
that :-)


Greg Stein, http://www.lyra.org/