[Types-sig] Re: Pascal style declarations

Roger Masse rmasse@cnri.reston.va.us
Wed, 15 Dec 1999 11:36:34 -0500 (EST)


Golden, Howard writes:
 > 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.)
 >
I don't want to further muddy the waters because I think Paul has some
really good ideas that he should start to run with... (I hope he has
the time and resources to write some code) The optional
static typing syntax has been talked about for quite some time...

IMHO specifying the return type as outlined in my static types paper
from last year's conference is more readable (i.e. return type of the
function *before* the parameter list). See dev-day review from last year
http://www.foretec.com/python/workshops/1998-11/dd-rmasse-sum.html
For example:

def myCallable : Int( i : Int, f : Float, m : myType):

...And parsable.  (Jon Reihl developed the grammar for the proposal)

Syntax is easy (contentious but easy), semantics that are "Pythonic"
and don't get in the way and *actually* improve safety is much harder.

    -Roger