Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-26 Thread Greg Ewing
Michael Chermside wrote: I've been following this conversation, and it sounds to me as if we are stumbling about in the dark, trying to feel our way toward something very useful and powerful. I think Jim is right, what we're feeling our way toward is macros. I considered saying something like that

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-26 Thread Greg Ewing
Michael Chermside wrote: if the answer is that we want to prohibit nothing, then the right solution is macros. I'm not sure about that. Smalltalk manages to provide very reasonable-looking user-defined control structures without using compile-time macros, just normal runtime evaluation together

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-26 Thread Rodrigo Dias Arruda Senra
[ Michael Walter ]: A couple of examples out of my tired head (solely from a user perspective) :-) Embedding domain specific language (ex.: state machine): ... Embedding domain specific language (ex.: markup language): ... Embedding domain-specific language (ex.: badly-designed

[Python-Dev] defmacro (was: Anonymous blocks)

2005-04-26 Thread Jim Jewett
(3) Add macros. We still have to figure out how to limit their obfuscation. nobody has given even a *remotely* plausible mechanism for how exactly you would get code executed at compile time. macros can (and *possibly* should) be evaluated at run-time. We must still have very

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-26 Thread Greg Ewing
Jim Jewett wrote: I had been thinking that the typical use would be during function (or class) definition. The overhead would be similar to that of decorators, and confined mostly to module loading. But that's too late, unless you want to resort to bytecode hacking. By the time the module is

RE: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Michael Chermside
Jim Jewett writes: As best I can tell, the anonymous blocks are used to take care of boilerplate code without changing the scope -- exactly what macros are used for. Folks, I think that Jim is onto something here. I've been following this conversation, and it sounds to me as if we are

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Shane Holloway (IEEE)
Michael Chermside wrote: Jim Jewett writes: As best I can tell, the anonymous blocks are used to take care of boilerplate code without changing the scope -- exactly what macros are used for. Folks, I think that Jim is onto something here. I've been following this conversation, and it sounds to me

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Aahz
On Mon, Apr 25, 2005, Shane Holloway (IEEE) wrote: Interfaces:: def interface(interfaceName, *bases, ***aBlockSuite): blockGlobals = aBlockSuite.globals().copy() blockGlobals.update(aBlockSuite.locals()) blockLocals = {} exec aBlock in blockGlobals,

[Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Jim Jewett
Guido: My problem with macros is actually more practical: Python's compiler is too dumb. I am assuming that we want to be able to import macros from other modules, and I am assuming that macros are expanded by the compiler, not at run time; but the compiler doesn't follow imports ...

RE: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Michael Chermside
Guido writes: My problem with macros is actually more practical: Python's compiler is too dumb. I am assuming that we want to be able to import macros from other modules, and I am assuming that macros are expanded by the compiler, not at run time; but the compiler doesn't follow imports (that

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Shane Hathaway
Robert Brewer wrote: So currently, all subclasses just override __set__, which leads to a *lot* of duplication of code. If I could write the base class' __set__ to call macros like this: def __set__(self, unit, value): self.begin() if self.coerce: value =

RE: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Robert Brewer
Shane Hathaway wrote: Robert Brewer wrote: So currently, all subclasses just override __set__, which leads to a *lot* of duplication of code. If I could write the base class' __set__ to call macros like this: def __set__(self, unit, value): self.begin() if

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Jim Jewett
On 4/25/05, Guido van Rossum [EMAIL PROTECTED] wrote: It could also be done (though not as cleanly) by making macros act as import hooks. Brrr. What about imports that aren't at the top level (e.g. inside a function)? Bad style already. :D If you want to use the macro, you have to ensure

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Guido van Rossum
It seems that what you call macros is really an unlimited preprocessor. I'm even less interested in that topic than in macros, and I haven't seen anything here to change my mind. -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Shane Hathaway
Robert Brewer wrote: I still prefer more methods, because my actual use-cases are more complicated. Your solution would work for the specific case I gave, but try factoring in: * A subclass which needs to share locals between begin and post, instead of pre and post. or * A set of 10

Re: [Python-Dev] defmacro (was: Anonymous blocks)

2005-04-25 Thread Samuele Pedroni
Robert Brewer wrote: Shane Hathaway wrote: Robert Brewer wrote: So currently, all subclasses just override __set__, which leads to a *lot* of duplication of code. If I could write the base class' __set__ to call macros like this: def __set__(self, unit, value): self.begin() if

[Python-Dev] defmacro (was: Anonymous blocks)

2005-04-23 Thread Jim Jewett
As best I can tell, the anonymous blocks are used to take care of boilerplate code without changing the scope -- exactly what macros are used for. The only difference I see is that in this case, the macros are limited to entire (possibly compound) statements. To make this more concrete,