J2 decorator grammar

Colin J. Williams cjw at sympatico.ca
Sun Aug 22 04:08:02 CEST 2004



Michael Sparks wrote:
> On Fri, 20 Aug 2004, Robert Brewer wrote:
> ...
> 
>>Did you ever fix the scope issue?
> 
> 
> I've fixed the scoping issue.
> 
> I'll clean up the changes I made to get a minimal patch against 2.4a2, and
> then put it somewhere handy. Now that I've got a much clearer idea of how
> the python source tree hangs together adding in the short form should be
> relatively simple.
> 
> The current patch uses "decorate" as the keyword. Changing that of course
> is utterly trivial - it's also something I think *should* be changed.
> 
> The reason for suggesting this change is for one simple reason - python
> makes often use of the idiom "decorate-dosomething-undecorate" - eg in
> sorting. Using decorate would probably clash heavily with people's code.
> 
> The closest word that strikes me that has a similar meaning to
> decorate, using and applying would be "decorating". If anyone has
> a closer suggestion to a short single word meaning "decorate using",
> it'd be great.
Since the action on the function (or [perhaps class) is transformative 
rather than decorative, would transform be a more appropriate word?
> 
Colin W.
> 
>>Might it have something to do with:
>>static void
>>symtable_node(struct symtable *st, node *n)
>>{
> 
> 
> It certainly did! Your suggested change was necessary, however it was
> incomplete - the child to traverse also needed changing. (I really
> should've thought of that sooner - of course it's no longer zero! :)
> 
> ie this
> 
>>                      symtable_node(st, CHILD(n, 0));
> 
> Becomes:
> 
>>                      symtable_node(st, CHILD(n, 4));
> 
> 
> So THANK YOU for pointing out this part of the code :)
> 
> Currently I have a file that looks like this, which is completely legal,
> and does what you would expect for this syntax:
> ----
> def memoise(f):
>    return f
> 
> class Foo:
>    decorate:
>       staticmethod
>    def Hoo(who):
>       print "You", who
>       if 1:
>          decorate:
>             memoise
>          def Print(what):
>             print "Ya", what
> 
>          Print(who)
> 
> Foo.Hoo("HOO!")
> ----
> 
> No matter what syntax we end up with, all of these syntactic sugar changes
> rely on the original decorator code, and I've been very pleasantly
> suprised at just how clean (and well documented) the python source is for
> a project of it's size.
> 
> As I say I'll post the cleaned up patch later.
> 
> Regards,
> 
> 
> Michael.
> 
> 




More information about the Python-list mailing list