lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rewrote convertrules.py with a decorator


From: Wilbert Berendsen
Subject: Re: rewrote convertrules.py with a decorator
Date: Fri, 20 Jun 2008 16:05:19 +0200
User-agent: KMail/1.9.9

Op vrijdag 20 juni 2008, schreef Han-Wen Nienhuys:
> This is an excellent idea. However, did you test this? AFAIK, the
> decorator needs to accept the function as input argument.

I tested it and it worked, I even verified that it really builds the same 
conversions list. :)

The function rule() returns another function that accepts the function as 
argument. This is because the decorator function itself also needs to accept 
arguments (version and message). This is the decorator function:

def rule (version, message):
    return lambda f: conversions.append ((version, f, message))

You could write this as:

def rule (version, message):
    """this function needs to return a function that is called with the
    function as argument"""
    def deco (function):
        conversions.append ((version, function, message))
    return deco

but the above version is shorter :-)
best regards,
Wilbert Berendsen

-- 
LilyKDE, LilyPond for KDE: http://lilykde.googlecode.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]