Feature Request: Scope..End Scope

BlitzMax Forums/BlitzMax Programming/Feature Request: Scope..End Scope

N(Posted 2006) [#1]
This would basically be nothing more than a scope. It has no conditions for use and such, it's just a way of organizing locals and setting up a specific scope for them.

E.g.,
Strict

Scope
  Local p! = Pi
  Print p
End Scope

Scope
  Local p% = Int(Pi)
  Print p
End Scope

Print p ' <- Would throw an error because p is part of the above scope


This really would only benefit people who use [Super]Strict as scopes are pretty much meaningless without it, but I think this would help for keeping things organized.


FlameDuck(Posted 2006) [#2]
Though I realize its not what you're asking for, you could just use
If true
..scoped stuff..
EndIf



N(Posted 2006) [#3]
Unfortunately, it still does a check to see if the condition is true, plus it just doesn't look very nice.

I did think about that, though.


RocketGnome(Posted 2006) [#4]
Actually, Noel (not to hijack your thread)...

But a similar implementation to what you mentioned above would be most useful if it were applied to an object:

Scope SomeObject:TList = new TList
   Local P:PlayerSprite = New PlayerSprite
   SomeObject.AddLast P
End Scope


Basically it would keep SomeObject alive for the duration of the Scope block.

This would act similarly to the "using" syntax of C# and (I think, Java).

The gain here would presumably be the same gain that you would get with other languages such that it provides a clear definition to BlitzMax of a particular object's life without the overhead of reference counts for the purposes of garbage collection.

Anyway.. just an idea.


N(Posted 2006) [#5]
I'd prefer that to just follow the same syntax as C# if Using were to be added.

E.g.,
Using SomeObject:TList = New TList
  Do some stuff to it
End Using
It's dead, yo



Grey Alien(Posted 2006) [#6]
I'd like to see Using as well.