Ronald Adam
Posts: 5
Nickname: ron100
Registered: Mar, 2005
|
|
Re: Adding Optional Static Typing to Python
|
Posted: Mar 14, 2005 5:02 PM
|
|
I'm proablaby a bit late in this, but maybe not.
How about adding an 'as' keyword? This would result in very readable prototype style definitions. I'm not sure how difficult this would be to do, but from a readability point of view, this seems to me to more consistant with pythons syntax.
def gcd(a, b) as int(int,int): while a: a, b = b%a, a return b
And possibly usefull in the case of classes:
class abd as constant: # read only pi = 3.14159265356 y = pi * 2 # this would be evaluated once
or single varibles:
a as int = 1 b as float = 3.5
The "as 'type'" statement would have the meaning of, "From now on, this name can only point to objects of this type."
So after which, if you want to assign a varable to something else you would need to remove the constraint or put on a new one.
a as int = 1 a as float = 5.4321 a = 3.14
a as none = 'what ever' # "as none" removes a type constraint
The arguments to 'as' might also be put into quotes as a string to reduce the need to create a whole set of key words... int, float, long, string... etc.
def gcd(a, b) as 'int(int,int)': while a: a, b = b%a, a return b
c as 'int' = 25 d as 'string' = 1.234 e as 'bool' = True
This form is very readable to me, something I've come to love and expect in python.
Ronald Adam radam2_at_tampabay.rr.com (replace _at_ to email)
|
|