type keyword proposal
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
I propose we add another design-by-contract feature like the class proposal.
I know these design-by-contract features aren't the sexiest things but I
think they give Prothon an advantage and when combined with the
extraordinary dynamic nature of Prothon give the best of all worlds.
This one is very simple. It is like a number of assert statements combined
into one statement. Each assert statement would be like:
assert var1.hasProto?(Proto1)
In other words these are assertions that variables are of a certain type.
The goal is to allow a number of these in one statement, and to allow each
assertion to allow for more than one prototype.
---- Type Proposal ----
type var1:proto1, (var2,var3):proto2, var4:(proto3, proto4)
If any var does not have the prototype after the colon (or one of the
prototypes in the tuple) in the var's prototype chain, then a TypeError
exception will be thrown.
This would usually be used immediately after the docstring in a function on
the params of the function, but could be used anywhere at any time on any
vars.
def func(a, b, c):
"a function"
type (a,b):int, c:(String, List)
Note that this would be the preferred way to document the types for the
auto-doc generator also. Note also the similarity to the original C typing
where the type was after the param list.
Comments? Votes?