[Types-sig] A challenge

Tim Peters tim_one@email.msn.com
Fri, 17 Dec 1999 05:23:56 -0500


[Christian Tismer]
> ...
> Just a question, please:
>
>> import fnmatch
>> import os
>>
>> decl _debug: Int  # but Boolean makes more sense; see below
>
> Is this meant to be lexically true in the globals scope from
> here on?

I'm not sure I grasp the question.  The implicit model is the "global" stmt:
a type declaration applies to the entire compilation unit in which it
appears (module, class or def), and referencing a declared name before the
declaration should be verboten.  "global" currently allows redundant
declarations, and you get a Fabulous Prize for later noticing the instance
of redundant type declarations that I snuck into one of the examples <wink>.
Conflicting declarations should be a compile-time error, and of the two
traditional approaches to that I vote for name equivalence (as opposed to
structural (content) equivalence).  That is:

class C1:
    decl member real, imag: Float
    real = imag = 0

and

class C2:
    decl member real, imag: Float
    real = imag = 0

are incompatible classes, despite that their guts are identical.

>> _debug = 0
>>
>> decl _prune: [String]
>> _prune = ['(*)']
>>
>> decl find: def(String, optional dir: String) -> [String]
>>
>> def find(pattern, dir = os.curdir):
>>     decl list, names: [String], name: String   # LINE1
>>     list = []
>>     names = os.listdir(dir)
>>     names.sort()
>>     for name in names:
>>         decl name, fullname: String            # LINE2

> Same question: "name" is redefined from here on?

My intent was to illustrate redundant declaration.  I'm definitely not
trying to invent new scoping rules!  The semantics would be exactly the same
if "name" were absent from either LINE1 or LINE2; it would be an error if
e.g. "decl name: Int" appeared in the "for" loop instead; and e.g. it would
be illegal to reference fullname before LINE2.

> Would this behave (or be as behaviorless) like
> the "global" declaration, or lexical, or do
> you open a new type scope with "for"? (New
> "variable, with C's {} in mind).
> The latter cannot be since "for" declared it already.

That's right.  No new scopes are implied here; just saying something about
the names in the current scopes.

how-do-we-declare-the-type-of-a-continuation<wink>?-ly y'rs  - tim