www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Local Function Scope Keyword

reply RicHardacre <ric.hardacre cyclomedia.co.uk> writes:
I wrote this up here:
http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=FeatureRequestList/LocalScopeOperator


the problem it attempts to solve is that sometimes you want to know what
function you are in and the "this" keyword won't help you unless you hardcode
all your function names in everywhere. instead i suggest the word "scope" (or
something else) to mean "the current function instance under the current class
instance" and possibly "this.scope" to find the class's entrypoint (the first
function called by an external class/function) 

I havent fully thought it through but i'm in the middle of some funky delegate
/ call stack shenanigans in c# and something like this would save me a bunch of
variables/hard coded function names and generally make it look cleaner.
Jan 17 2008
next sibling parent downs <default_357-line yahoo.de> writes:
RicHardacre wrote:
 I wrote this up here:
http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=FeatureRequestList/LocalScopeOperator
 
 
 the problem it attempts to solve is that sometimes you want to know what
function you are in and the "this" keyword won't help you unless you hardcode
all your function names in everywhere. instead i suggest the word "scope" (or
something else) to mean "the current function instance under the current class
instance" and possibly "this.scope" to find the class's entrypoint (the first
function called by an external class/function) 
 
 I havent fully thought it through but i'm in the middle of some funky delegate
/ call stack shenanigans in c# and something like this would save me a bunch of
variables/hard coded function names and generally make it look cleaner.

Vote in favor, not that anybody cares. self as a keyword is still free :) --downs
Jan 17 2008
prev sibling parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
RicHardacre wrote:
 I wrote this up here:
http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=FeatureRequestList/LocalScopeOperator
 
 
 the problem it attempts to solve is that sometimes you want to know what
function you are in and the "this" keyword won't help you unless you hardcode
all your function names in everywhere. instead i suggest the word "scope" (or
something else) to mean "the current function instance under the current class
instance" and possibly "this.scope" to find the class's entrypoint (the first
function called by an external class/function) 
 
 I havent fully thought it through but i'm in the middle of some funky delegate
/ call stack shenanigans in c# and something like this would save me a bunch of
variables/hard coded function names and generally make it look cleaner.

I like the idea though scope probably shouldn't be reused for this purpose. Python uses something similar a __name__ variable which can be checked to see if the code is been executed as the main module: if '__main__' == __name__: print "I'm the main module." However, I would have implemented the example as follows: public void AddNewUser( string Name ) { Lock l = Database.tblUsers.Lock(); Add( Name, l ); l.Unlock(); } public void AddNewUser( string Name, Lock l ) { Database.tblUsers.Insert( Name, l ); } public void AddUsers( string[] Names ) { Lock l = Database.tblUsers.Lock(); foreach( string Name in Names ) AddNewUser( Name, l ); l.Unlock(); } Also, I would love to have __FUNCTION__ and __CLASS__ compile time variables in D like there are in PHP. It would simplify logging. Cheers. -- Julio CÚsar Carrascal Urquijo http://jcesar.artelogico.com/
Jan 17 2008