Carl Sorensen <c_soren...@byu.edu> writes: > On 12/26/11 12:50 PM, "David Kastrup" <d...@gnu.org> wrote: >> >>Actually, what about the following rather minimalistic approach? >>#(define-macro (make-engraver . translist) >> (define (make-lambdas translist) >> `(list >> ,@(map (lambda (x) >> (if (pair? (car x)) >> `(cons ',(caar x) (lambda ,(cdar x) ,@(cdr x))) >> `(cons ',(car x) ,(make-lambdas (cdr x))))) >> translist))) >> (make-lambdas translist)) > > Very nice! The only think that I think ought to be added would be some > way of storing a global status variable in the engraver, as they are > frequently used. The status variable should be persistent between calls > to the engraver, I think.
What's to be added? The following works as expected (including the expected warnings...).
#(define-macro (make-engraver . translist) (define (make-lambdas translist) `(list ,@(map (lambda (x) (if (pair? (car x)) `(cons ',(caar x) (lambda ,(cdar x) ,@(cdr x))) `(cons ',(car x) ,(make-lambdas (cdr x))))) translist))) (make-lambdas translist)) \header { texidoc = "Scheme engravers may be instantiated, with instance-scoped slots, by defining a 1 argument procedure which shall return the engraver definition as an alist, with the private slots defined in a closure. The argument procedure argument is the context where the engraver is instantiated." } \version "2.14.0" \layout { \context { \Voice \consists #(let ((instance-counter 0)) (lambda (context) (set! instance-counter (1+ instance-counter)) (let ((instance-id instance-counter) (private-note-counter 0)) (make-engraver (listeners ((note-event engraver event) (set! private-note-counter (1+ private-note-counter)) (let ((text (ly:engraver-make-grob engraver 'TextScript event))) (ly:grob-set-property! text 'text (format #f "~a.~a" instance-id private-note-counter))))))))) } } << \relative c'' { c4 d e f } \\ \relative c' { c4 d e f } >>
-- David Kastrup
_______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel