Keyword for nameless scope

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Keyword for nameless scope

Post by Mistrel »

#NULL wrote:
Mistrel wrote:Is there a use case for a Module/EndModule without a DeclareModule/EndDeclareModule?
Good question :) I think you could wrap any code in a module for encapsulation and the module will execute itself wherever it's included, even though nothing could be called from outside.

Code: Select all

DeclareModule msg
EndDeclareModule
Module msg
  m.s = "hello"
  MessageRequester("msg", m)
EndModule
viewtopic.php?p=524830#p524830

I was going to propose this as a feature request but I think a new keyword block would make the most sense:

Code: Select all

Scope
EndScope
This would give us something akin to Modules but with no ability to reference anything declared within. The advantages would be:
  • Variable names can be re-declared as different types later.
  • Nameless scopes can be created and used anywhere and in places that modules cannot (such as in procedures).
And most importantly:
  • Scopes would inherit their parent scope (which modules do not).