[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: book-predicate
From: |
David Kastrup |
Subject: |
Re: book-predicate |
Date: |
Sun, 04 Mar 2012 11:14:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) |
Jan-Peter Voigt <address@hidden> writes:
> 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))")
What's with the eval-string nonsense? Why don't you just use
(define-module (a b)) instead?
> 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.
> 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?
--
David Kastrup