Comment #11 on issue 2872 by [email protected]: Patch: Provide define-session and define-session-public commands
http://code.google.com/p/lilypond/issues/detail?id=2872

add-new-clef is a public function, and it is unlikely that anybody changes this function from one session to the next. Instead, it is getting used. If we take a look at this function, we see (define-public (add-new-clef clef-name clef-glyph clef-position octavation c0-position)
  "Append the entries for a clef symbol to supported clefs and
@code{c0-pitch-alist}."
  (set! supported-clefs
(acons clef-name (list clef-glyph clef-position octavation) supported-clefs))
  (set! c0-pitch-alist
        (acons clef-glyph c0-position c0-pitch-alist)))

And this means that we want to reset supported-clefs and c0-pitch-alist at the start of the next session. Those are defined with define-public and define, respectively, so you can replace them with define-session-public and define-session. Why is supported-clefs public? There is an incredibly stupid thing called memoize-clef-names in scm/define-music-display-methods that will only work the first time it is called. So we want to replace the "memoize location" defined with
(define clef-name-alist #f)
also with a define-session, so that this will work more often than just in a single session. It would actually make more sense to remember the last _supported-clefs_ for memoization (rather than just a flag), and if it is not eq? to the current supported-clefs, it gets regenerated. In that manner, one can even do memoization across sessions (meaning that clef-name-alist and last-supported-clefs themselves don't need to be per-session) and only have clef-name-alist recalculated if last-supported-clefs is no longer the eq? to supported-clefs since last use.


Reply via email to