On 12/24/2014 11:15 PM, I wrote:
> I’m trying to figure out a generic way to do a *shallow* copy of 
> heterogeneous structures (i.e., to traverse and copy unmodified as a 
> starting point, before introducing the few small modifications I want
> to make).  Searching hasn’t turned up anything other than 
> ly:music-deep-copy... if anyone has a pointer to a template for
> this, I’d be grateful.

OK!

At <URL: http://crism.maden.org/music/swing.ly > is an updated version,
which seems to be working.  Comments welcome, as are use and redistribution.

As for the generic shallow copy, the thing I made as a starting point
for this is below, in case anyone else finds it useful for making a
slightly-modified copy of some music.

#(define (my-copy some-music)
   (cond
    ((ly:music? some-music)
     (let ((elt (ly:music-property some-music 'element))
           (elts (ly:music-property some-music 'elements))
           (new-music (ly:music-deep-copy some-music)))
       (cond
        ((not (null? elts))
         (ly:music-set-property! new-music 'elements (my-copy elts)))
        ((not (null? elt))
         (ly:music-set-property! new-music 'element (my-copy elt)))
        )
       new-music))
    ((list? some-music)
     (map my-copy some-music))
    (#t
     (ly:music-deep-copy some-music))))

~Chris
-- 
Chris Maden, text nerd  <URL: http://crism.maden.org/ >
Surround hate and force it to surrender.
GnuPG fingerprint: DB08 CF6C 2583 7F55 3BE9  A210 4A51 DBAC 5C5C 3D5E

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to