lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #(define (bookGenerator please))


From: Urs Liska
Subject: Re: #(define (bookGenerator please))
Date: Tue, 17 Nov 2015 09:02:12 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0



Am 17.11.2015 um 03:12 schrieb Pierre-Luc Gauthier:
So, after reading the "Automated processing of multiple books" thread
and few hours trying to figure this out, I am still not able to make
it work.
The higher order function "for-each" somehow cannot call the
"compilePart" function and Lilyponds GUILE interpreter returns "Wrong
type to apply".

Why?

This is because you did not pass a music _expression_ but a symbol.
The problem is in the definition of the "parts" variable. This is defined to be a list of pairs (which is right) but in

' ("piccolo" . piccoloPart)

the leading quotation mark makes the elements of the following pair or list "quoted" as well. So it's basically the same as

(list "piccolo" 'piccoloPart)

If you want to use the "quote" style definition but need some of the elements to be treated as their actual value instead of simply names we have the "quasiquote" style where you precede the parenthesis with a backtick:

`(item1 . item2)

`("piccolo" . piccoloPart)

however would result in the same error. But if you have "quasiquoted" an _expression_ you can "unquote" individual elements using the comma:

`("piccolo" . ,piccoloPart)

finally works.

So

parts = #(list
          ;; This is a list of pairs containing parts informations
          `("piccolo" . ,piccoloPart)
          `("bass" . ,bassPart))

will make your file compile and produce two parts

HTH
Urs



Simple tests allowed me to prove that "for-each" *can* call functions
like "display" but not my "compilePart".

I am very very new to scheme and let alone scheme inside the pond and
I really got a kick out of this journey finally understanding why
those #, #', #{, #}, $, parser, location, etc were there in the first
place.
It's really satisfying.

Here is the code for my MWE.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.18.2"

\language "english"

piccoloPart = \new Staff {
  \new Voice {
    \relative c' {
      d4 e fs g |
      a1\fermata |
    }
  }
}

bassPart = \new Staff {
  \new Voice {
    \relative c {
      \clef bass
      c4 d e f |
      g1\fermata |
    }
  }
}

compilePart = #(define-void-function ( parser location music name)
                 ;; This function is used to do and engrave a book
                 ;; $music should be a musical _expression_
                 ;; $name should be a string for the book output suffix
                 (ly:music? string?)
                 (let ((paper #{ \paper {} #})
                       (layout #{ \layout {} #})
                       (book #{ \book { \score { $music } } #}))
                   (ly:book-process book paper layout name)))

% _This_ is to test the compilePart function
%\compilePart \piccoloPart #"piccolo"
% \compilePart \bassPart #"bass"

parts = #(list
          ;; This is a list of pairs containing parts informations
          '("piccolo" . piccoloPart)
          '("bass" . bassPart))

% _This_ is to test that the data can be extracted succesfully from the list
%\compilePart #(cdr (car parts)) #(car (car parts)) % First entry
%\compilePart #(cdr (car (cdr parts))) #(car (car (cdr parts))) % Second entry

% Somehow _this_ does not work.
%{#(for-each
  (lambda (p)
    (let ((name (car p))
  (music (cdr p)))
    (compilePart music name )
    ))
  parts)%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

2015-11-16 14:55 GMT-05:00 Pierre-Luc Gauthier <address@hidden>:
Possible duplicate!

It appears I have missed the very similar thread "Automated processing
of multiple books"

I'll digest that first ;-)

--
Pierre-Luc Gauthier




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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]