lilypond-user
[Top][All Lists]
Advanced

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

Re: How to store lengths in variables


From: David Kastrup
Subject: Re: How to store lengths in variables
Date: Tue, 12 Dec 2017 15:14:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Urs Liska <address@hidden> writes:

> Thank you. While I had to figure out how to adapt this to 2.18 I
> realized that the missing information was that I can turn the symbol
> "cm" into a value through ly:parser-lookup.
>
> This works with 2.18, and I will further refine it (the idea is to
> store several sets of paper variables and select a set with a single
> function:
>
> \version "2.18"
>
> #(define paper-values
>    '((top-margin . (5 . cm))
>      (indent . (4 . cm))))

Can you tell your mail client _not_ to replace spaces with unbreakable
spaces?  This makes copy&paste much less pleasant.  At any rate, I'd
likely go for

'((top-margin . (* 5 cm))
  ....

instead.  You can even use

'((top-margin . #{ 5\cm #})
 ....

and either will yield to primitive-eval when in a paper module.

> #(define-scheme-function (parser location val)(symbol?)
>    (let*
>     ((entry (assoc-ref paper-values val))
>      (unit (ly:parser-lookup parser (cdr entry))))
>      (* unit (car entry))))
>
> \paper {
>   indent = \paperValue #'indent
>   top-margin = \paperValue #'top-margin
> }

Why not just
\paper {
  #(for-each (lambda (p)
               (ly:parser-define! (car p) (primitive-eval (cdr p))))
             paper-values)
}
or some suitably similar wrapper?

-- 
David Kastrup



reply via email to

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