I know what a decorator is - I'm sorry for thinking it didn't work, but the code is a bit obtuse, and I got confused by
return lambda f: conversions.append ((version, f, message)) which stores the conv function, but then will also redefine the conv function to None. Essentially it does def dec(f): return None @dec def f(x): return 1 print f => None Can you document this more clearly so it does not look so strange? Also the patch should look like a proper commit, with description prepended and your name attached as author. On Tue, Jul 1, 2008 at 8:03 PM, Wilbert Berendsen <[EMAIL PROTECTED]> wrote: > Op woensdag 2 juli 2008, schreef Han-Wen Nienhuys: >> I already wrote a comment about this before, but I strongly doubt that >> this does anything useful. > > The useful thing is dat a conversion rule now forms a single entity: version, > message and conversion function. > > The current structure of convertrules.py is a bit error-prone: the function > definition comes first and then the conversions.append method adds the > version, a pointer to the latest definition of 'conv' and a message the the > conversions list. > > My proposal is to use a decorator (we're requiring Python 2.4 anyway) so the > version a conversion function applies to is clearly connected with the > function and the message it outputs. > >> Have you tested this at all? > > Yes: I verified that the decorator based code just builds the same list in the > conversions variable as the old code by diffing the repr() output of both > lists. > > This is just a proposal to make convertrules.py look better, more clear and > probably a little bit easier to maintain. Because you wrote in your first > answer "This is an excellent idea" I kept up maintaining it. If it gets > rejected, no problem, the old code works equally well. But IMHO, using a > decorator is a perfect fit for convertrules.py. > > To summarize: with a decorator a conversion rule is really a single entity: > > ------------snip----------- > @rule ((1, 2, 3), _("convert foo to bar")) > def conv(str) > str = str.replace('foo', 'bar') > return str > ------------snip----------- > > in the old code, those are separated, and the conversion.append() command is > repeated every time instead of hiding that implementation detail: > > ------------snip----------- > def conv(str) > str = str.replace('foo', 'bar') > return str > > conversions.append(((1, 2, 3), conv, _("convert foo to bar"))) > ------------snip----------- > > best regards! > Wilbert Berendsen > > -- > LilyKDE, LilyPond for KDE: http://lilykde.googlecode.com/ > -- Han-Wen Nienhuys - [EMAIL PROTECTED] - http://www.xs4all.nl/~hanwen _______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel