4

I have pitch names defined as a alist in Lilypond as below and it works fine. \version "2.18.2"

pitchname = #`(
                (saa . , (ly:make-pitch -1 0 NATURAL))
                (raa . , (ly:make-pitch -1 1 FLAT))


                (sa . , (ly:make-pitch -1 0 NATURAL))
                (ri . , (ly:make-pitch -1 1 FLAT))
                (ga . , (ly:make-pitch -1 2 NATURAL))                 
                )                               

#(ly:parser-set-note-names parser pitchname)

musicA = \relative sa' { sa4 ri ga sa ri ga sa ri ga ri saa ga ri sa ga raa  }

\score {\musicA}

I would like to define the variable pitchname as sum/join/append/cons of two a lists, as below:

     firstpart = #`(
                    (saa . , (ly:make-pitch -1 0 NATURAL))
                    (raa . , (ly:make-pitch -1 1 FLAT))
                   )

    secondpart = #'(
                     (sa . , (ly:make-pitch -1 0 NATURAL))
                    (ri . , (ly:make-pitch -1 1 FLAT))
                    (ga . , (ly:make-pitch -1 2 NATURAL))               
                    )

and combine the two, say:

pitchname = (cons #firstpart #secondpart)

The last statement combining the two parts is not working. Can someone tell me what I am doing wrong here?

Elements in Space
  • 10,785
  • 2
  • 23
  • 67
Jay Vara
  • 81
  • 1
  • `cons` does *not* concatenate lists. It *constructs* list. The result of `(cons head tail)` is a list whose first element is `head` then followed by the elements of `tail`. – Édouard Sep 14 '14 at 10:34

2 Answers2

1
pitchname = #(append firstpart secondpart)
Édouard
  • 3,867
  • 1
  • 21
  • 32
user13414
  • 11
  • 1
1

There are two issues with your code.

  1. As others noted, what you really want to do is append the alists. (Also, you forgot the leading # to escape from Lilypond to Scheme.) For comparision, this is what using cons instead would do. Note how the elements don't end up at the same nesting depth:
    pitchname = `(((saa . , (ly:make-pitch -1 0 NATURAL))
                   (raa . , (ly:make-pitch -1 1 FLAT)))
                  (sa . , (ly:make-pitch -1 0 NATURAL))
                  (ri . , (ly:make-pitch -1 1 FLAT))
                  (ga . , (ly:make-pitch -1 2 NATURAL)))
  1. Your second list is quoted (straight apostrophe) instead of quasiquoted (backtick). You do want those make-pitch calls to be evaluated, so you can't go around the quasiquoting here.
J B
  • 205
  • 3
  • 9