[Types-sig] New syntax?

Greg Stein gstein@lyra.org
Fri, 17 Dec 1999 01:16:09 -0800 (PST)


On Thu, 16 Dec 1999, Tim Peters wrote:
> [GregS]
> > ...
> > 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 thought it would be easier to get one new stmt than to modify existing
> stmts, and *much* easier to write a dirt-simple tool to strip them out again
> (vis a vis Guido's requirement).
> 
> In real life I would certainly prefer annotating "def" stmts directly.  I
> think a declaration statement needs the *ability* to specify full function
> signatures, though; e.g.,
> 
> decl handlerMap: {String: def(Int, Int)->Int}

Ah. Right. Good point. I guess that does mean that something like:

decl a: def(Int)->None

would be possible. e.g. <a> is a member holding a ref to a function
object. Of course, the type of <a> in this case is no different than:

def a(Int x)->None:

It is just that one declares a member and the other declares a method.
There is a subtle difference there :-)

In fact, these two are probably equivalent:

decl class a: def(Int)->None
def a(Int x)->None:

> handlerMap = {"+": lambda x, y: x+y,
>               "*": lambda x, y: x*y,
>               ...
>              }
> 
> In either case, I'm not sure what to do about varargs (the "*rest" form of
> argument).

What's wrong with:

decl a: def(Int, *)->Int
decl b: def(Int, **)->Int
decl c: def(Int, *, **)->Int

I don't see any ambiguity in the grammar there, unless you use "*" to mean
unknown (as Paul once mentioned). I think the unknown type should be
"Any" (or "any"), since it really means "take any type of value."

> > ...
> > 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.
> 
> I am:  I didn't think about this at all.  Member vrbls are far more common
> than class vrbls, so practicality beats purity <wink>.

That was my first thought. Then I started thinking too hard about the
problem... :-)

I'm not sure whether to go for practical or pure.

Cheers,
-g

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