lilypond-user
[Top][All Lists]
Advanced

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

Re: book-predicate


From: Jan-Peter Voigt
Subject: Re: book-predicate
Date: Sun, 04 Mar 2012 10:09:07 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

Hello David,

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

I assume, the string-eval approach loads up the whole guile-tool-chain, so that define is defined.
The function I am thinking of shall work like this:

<pseudo-snip>
#(define-public (set-book-headers! book header) ; book is a book, header is an a-list, containig all vars to inject into header
  (let ((bookhead (ly:book-header book)))
       ; if book has no header, create one
       (if (not bookhead) (let ((bh (/make-module/)))
                (set! bookhead bh)
                (ly:book-set-header! bookhead)
       ))
       (for-each (lambda (p)
                         (if (pair? p)
                             (let ((key (car p))
                                   (val (cdr p)))
                                  (/inject key=val/ bookhead))))
                 header)
))
</pseudo-snip>

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))")
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. 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. My function shall modify the given book and not create a new one, so that the change is visible outside the function-scope. Of course, one might return the changed/copied book and use that for processing, but I still like to know the answers to my questions? ;-)

Happy sunday!
Cheers, Jan-Peter


make-module would be obvious.
But if you try a (eval '(define title "Titel") (make-module)) it fails
with "Unbound variable: define"?
Well, where would a definition for "define" come from in an empty
module?





reply via email to

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