[Types-sig] Re: Pascal style declarations

Paul Prescod paul@prescod.net
Tue, 14 Dec 1999 18:03:24 -0800


Greg Stein wrote:
> 
> "int" is a valid expression, which is valid on the same line after a
> function definition. For example:
> 
>   def funx(x, y): foo() ; return 5

Well, first, I don't think that we are going to allow functions as
return type specifications. Use assert for runtime assertions.

Second, Python needs to use look-ahead to tell the difference between
parentheses used for parsing a tuple and used for bracketing, doesn't
it?

> We already have expr-based (the "assert" statement) -- we can assert types
> on expressions anywhere. It is just a little less convenient since we must
> place the expression value into a temporary variable, assert the type of
> that, then continue with the expression. The "type-assert operator"
> simplifies this process dramatically.

Sure, but why not just use function call syntax? Or maybe Java/C++
(cast) syntax?

> Jeremy wrote:
> > I think I agree with you as far as local variables.  It becomes quite
> > interesting when you're talking about attributes of objects, e.g. what
> > is the type of the closed attribute of a builtin file object.  (For
> > that matter, what is the type of the builtin open function and how
> > does it differ from a function that returns a StringIO object?)
> 
Greg Stein wrote:
> Ah! Good point. I think this is where interfaces come in. Otherwise, it
> becomes very difficult to syntactically specify the types of attributes.

When we specify the types of attributes, we will be talking about those
attributes by name, not by expression or value. So we need a syntax for
specifying types of names *and* expressions. If we use function syntax
for expressions casts then we can reduced the syntactic overload.

-- 
 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
Three things to be wary of: A new kid in his prime
A man who knows the answers, and code that runs first time
http://www.geezjan.org/humor/computers/threes.html