[Types-sig] Pascal style declarations
Tony Lownds
Tony Lownds <tony@metanet.com>
Tue, 14 Dec 1999 13:46:03 -0800 (PST)
Hi,
Visual Basic uses "as" to declare types of parameters, and
Object Pascal uses "as" as a dynamic cast operator, so consider "as"
instead of !
I'll use that below just to try it on for size. My main point is, I think
there should be a seperate operator for declaring return types. If I read
your proposal right, then
def logfn(s as String, *args) as String:
...
declares that log is a reference to a function taking a sting and a bunch
of unspecified types, returning a string. How would you check that an
object is a function with the same signature?
# programmer would have to think associativity here
log = logfn as (String, *Object) as String
That syntax doesnt seem to be easily grokkable. Now if you had another
operator that declared return values, say ->, then the statement above is
clearer and you could also make a typedef for a function and apply it in
the def statement.
def logfn(s as String, *args) -> String:
...
log = logfn as (String, *Object) -> String
-or-
log_function = (String, *Object) -> String
def logfn(s, *args) as log_function:
...
log = logfn as log_function
Tim H. also mentioned using -> but he suggested replacing ! with ->, I am
suggesting that we'd want a seperate operator for declaring return
types.
-Tony Lownds
On Tue, 14 Dec 1999, Greg Stein 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...
>
> This was one reason that Fred/Sjoerd/myself moved away from ':'-based
> declarations, and eventually fell into expression-based type checking.
>
> Cheers,
> -g
>
>
> On Tue, 14 Dec 1999, Golden, Howard wrote:
>
> > Since Guido hasn't had a coronary in response to my earlier suggestion, I
> > will be more specific:
> >
> > 1. I propose _optional_ typing, using the Pascal syntax (since this seems
> > to me to be the most "Pythonic" (Isn't that like giving a snake an enema?
> > Sorry.). Actually, I don't care about the specific syntax, just as long as
> > there is one.
> >
> > 2. Specifically, you can declare a variable using the syntax:
> >
> > var x : int, y : string, ...
> >
> > 3. In functions and methods, you can _optionally_ specify the argument
> > type:
> >
> > def funx(x : int, y : string): ...
> >
> > 4. If you use these, then you are making binding assertions about the types
> > of the names, and these assertions can be checked at compile or run time.
> >
> > 5. The parser could be made to strip out these declarations, and ignore
> > them, in which case they would have no effect.
> >
> > 6. The parser should be modified so you can tell it (using a compile-time
> > switch or pragma) to require declarations.
> >
> > 7. It appears to me that this would not change existing code, except if it
> > uses the name "var".
> >
> > 8. I think there should be a parameterized type mechanism. I don't much
> > like the angle bracket notation of C++, but I guess it's well established,
> > so it'll do.
> >
> > In my opinion, this doesn't "muck up" the language (since you don't have to
> > use it).
> >
> > ---
> >
> > Howard B. Golden
> > Software developer
> > Litton Industries, Inc.
> > Woodland Hills, California
> >
> >
> > _______________________________________________
> > Types-SIG mailing list
> > Types-SIG@python.org
> > http://www.python.org/mailman/listinfo/types-sig
> >
>
> --
> Greg Stein, http://www.lyra.org/
>
>
> _______________________________________________
> Types-SIG mailing list
> Types-SIG@python.org
> http://www.python.org/mailman/listinfo/types-sig
>