[Python-Dev] A Hygienic Macro System in Python? (original) (raw)
Duncan Booth duncan@rcp.co.uk
Tue, 19 Mar 2002 12:20:45 +0000
- Previous message: [Python-Dev] A Hygienic Macro System in Python?
- Next message: [Python-Dev] A Hygienic Macro System in Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 18 Mar 2002, Skip Montanaro <skip@pobox.com> wrote:
I think a "lock" keyword would be appropriate:
lock somelock: do stuff The biggest problem I found with the try/finally lock idiom was that "do stuff" can tend to get long, so the vertical distance between lock.acquire() and lock.release() can be substantial. a lock statement/clause/macro would remove the need to worry about that visual distance.
This is one of the areas that I think Microsoft got right in C#. C# has a using statement: using (resource-acquisition) embedded-statement where resource-acquisition is a local variable declaration or a expression that creates an object with an IDisposable interface.
The using statement effectively wraps a try..finally around the embedded statement, and the finally calls the Dispose method of the object created in the resource-acquisition part.
I guess a direct translation into Python would be: using assignment_stmt: suite and: using expression: suite
Which would be roughly equivalent to: usingvar = assignment_stmt (or expression) try: suite finally: if isinstance(usingvar, tuple): for item in usingvar: item.Destroy() else: usingvar.Destroy()
-- Duncan Booth duncan@rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
- Previous message: [Python-Dev] A Hygienic Macro System in Python?
- Next message: [Python-Dev] A Hygienic Macro System in Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]