[Types-sig] Re: Pascal style declarations
Golden, Howard
GoldenH@littoncorp.com
Tue, 14 Dec 1999 13:45:53 -0800
Greg Stein [mailto:gstein@lyra.org] wrote:
> You don't provide a way to declare function return value(s)
> types. When
> you do, then I think you're going to run into a problem using the ':'
> syntactical marker...
[refers to:]
> > 3. In functions and methods, you can _optionally_ specify
> the argument
> > type:
> >
> > def funx(x : int, y : string): ...
> >
I'll admit that Python already uses the ":" character where Pascal does, but
so what? You can still specify the return type in other ways. The most
obvious (to me) is to use the ":" character twice, e.g.,
def funx(x : int, y : string): int : ...
While I'm not a parsing expert, I believe this would still be parsable. Of
course, any other available character could be used instead of the ":", if
this would be preferable. (Again, I'm not trying to dictate the final
syntax, just suggest a starting point.)
> This was one reason that Fred/Sjoerd/myself moved away from ':'-based
> declarations, and eventually fell into expression-based type checking.
I am suggesting using declarations, rather than expression-based type
checking, since that is familiar in other languages. As a declaration, it
is clear that I am talking about an invariant assertion, not a dynamic one.
Expression-based type checking should also be available, since it is needed
when static checking is impossible. I don't think it has to be either/or.