[Prev][Next][Index][Thread]

Re: Q: statements in module file?



On Monday, June 25, 2001, at 05:30  pm, Roland Paterson-Jones wrote:

> It seems to me that you can have arbitrary statements at the top-level 
> in
> dylan (i.e. in between the method and class definitions).

Yes, you can. main() is called in this way, and various registration 
methods and initializers in libraries work in this way.

> What is the exact semantics of this?

Well, just about any Dylan code can go in IIRC, but you can't do lets 
unless you put them in a block. I think the code effectively gets 
gathered up and put into an anonymous initialize method for the module. 
As for execution order I'd imagine it's parse order.
It's cleanest to gather this code into a method and put a call to the 
method at the top-level if you've more than a line or two of code like 
this.

> Do the statements only have access to the definitions
> appearing above them in the source file?

No, they're compiled lazily like methods and classes (but not macros, 
apparently). Dylan is a modern programming language, it's there for the 
benefit of the user not the compiler. :-)

- Rob.


References: