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?

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, 2014 at 10:34

2 Answers 2

1
pitchname = #(append firstpart secondpart)
1
  • Tried that - says error: not a symbol pitchmane = (append #firstpart #secondpart)
    – Jay Vara
    Sep 13, 2014 at 19:35
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.