Hello David,

thank you for answering!
Now I know about (make-module) and (module-define! ...) - these are the two I was missing, while reading the guile 1.8 docs ...

So these are the set-book/score-headers! functions:
--snip--
(define-public (set-book-headers! book header)
  (let ((bookhead (ly:book-header book)))
       ; if book has no header, create one ... needs "ly:book-set-header!"
;(if (not bookhead) (let ((mod (make-module))) (set! bookhead mod) (ly:book-set-header! book bookhead)))
       (for-each (lambda (p)
                         (if (pair? p)
                             (let ((key (car p))
                                   (val (cdr p)))
(module-define! bookhead key val)))) header)
))
(define-public (set-score-headers! score header)
  (let ((scorehead (ly:score-header score)))
       ; if score has no header, create one
(if (list? scorehead)(let ((mod (make-module))) (set! scorehead mod) (ly:score-set-header! score scorehead)))
       (for-each (lambda (p)
                         (if (pair? p)
                             (let ((key (car p))
                                   (val (cdr p)))
(module-define! scorehead key val)))) header)
))
--snip--

Another thing to mention: Thank you David, for answering so quickly ...

@GNU admins or who else is in charge:
The e-mail took quite a time to reach me, there is a lack of about 6 hours in the received-headers. This is not a problem for me, but this might lead to twice-sent-posts or confusion, "why is nobody answering?"
--snip--

...
Received: from localhost ([::1]:57392 helo=lists.gnu.org)
        by lists.gnu.org with esmtp (Exim 4.71)
        (envelope-from *******)
        id *******
        for *******; Sun, 04 Mar 2012 11:38:12 -0500
Received: from eggs.gnu.org ([208.118.235.92]:38688)
        by lists.gnu.org with esmtp (Exim 4.71)
        (envelope-from<gnu-lilypond-u...@m.gmane.org>) id *******
        for lilypond-user@gnu.org; Sun, 04 Mar 2012 05:14:45 -0500
...

--snip--

Cheers, Jan-Peter

On 04.03.2012 11:14, David Kastrup wrote:
Jan-Peter Voigt<jp.vo...@gmx.de>  writes:

sorry for this kind-a-basic-scheme-question(s) ... ;-)
How do I inject variables into an empty module?

...

So AFAICS there are at least 3 different ways to create a module to
use in a header:
1: (eval-string "(define-module (a b))")
What's with the eval-string nonsense?  Why don't you just use
(define-module (a b)) instead?
because: "define-module can only be used at the top level"
2: (ly:book-header #{ \book { \header { } } #})
3: (make-module)

The first two are some kind of cheating, but create modules, where I
can inject my vars using
(eval `(define ,key (quote ,val)) bookhead)

I would prefer the 3rd one, if I knew, how to inject the vars inside
the empty module.
(module-define! module key val)

Not all that hard.
yes, that is right!

In my first post, regarding this stuff, I used eval-string, because I
assume it produces less overhead than creating a book in inline
lily-code.
Sure, but why eval-string?  Why not write what you want instead?
see above, I just didn't find "make-module" and "module-define!" in the docs.



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

Reply via email to