So after 56 years of programming I've at last got around to writing some Lisp, 
and of course it doesn't work.

I'm trying to define a routine repeat-verses which would be used like

\repeat-verses 3 \music

which would have the effect of

\keepWithTag #'v1 \music
\keepWithTag #'v2 \music
\keepWithTag #'v3 \music

I came up with this code:

repeat-verses =
#(define-music-function ( count     music  )
                        ( index? ly:music? )
   (make-music 'SequentialMusic 'elements
     (map-in-order
      (lambda (verse)
       (begin
        (define versenum
         (string->symbol (string-join (list "v" (number->string verse)) "" )))
         #{ \keepWithTag #versenum #music #})) 
      (iota count 1))))

which doesn't quite work. It's as though no tags are defined, so anything in 
\music which is surrounded by a tag is omitted.

Replacing the definition of versenum with (define versenum 'v1) works fine, 
although of course you get three copies of verse one, and replacing  the 
definition of versenum with

        (define versenum
         (string->symbol (string-join (list "v" (number->string 1)) "" )))

(i.e. not using the value of variable verse) also works with three copies of 
verse one.

So two questions:
 1. Why doesn't this work; and
 2. How should I really go about solving this problem?
Kevin.

Reply via email to