lilypond-user
[Top][All Lists]
Advanced

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

Re: Procedure for set-paper-size in \paper ?


From: David Kastrup
Subject: Re: Procedure for set-paper-size in \paper ?
Date: Sat, 19 May 2018 09:45:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Thomas Morley <address@hidden> writes:

> Hi all,
>
> (1)
> consider the following code (working as expected):
>
> \paper {
>   #(if #t (set-paper-size "a8" 'landscape) #(set-paper-size "a8"))
> }
>
> \score { { R1 } \layout { ragged-right = ##f } }
>
> Switching from #t to #f results in different paper-size, as desired.

Unlikely as you write #(set-paper-size ...) here, see below.

>
> (2)
> But trying to put it in a procedure, it always returns the true-case:
>
> #(define (proc bool x y)
>   (if bool x y))
>
> \paper {
>   #(proc #f (set-paper-size "a8" 'landscape) #(set-paper-size "a8"))
> }

Uh, the return value is irrelevant.  It always _executes_ the true case.
It also executes the false case but that is not overly interesting since
the false case is a vector consisting of the elements 'set-paper-size
and "a8" since you write #(...) while already in Scheme, the syntax for
vector literals.

Now if you want to execute only conditionally, you either need to wrap
in lambdas or use a macro rather than a procedure:

#(define-macro (proc bool x y)
   (if bool x y))

\paper {
  #(if #t (set-paper-size "a8" 'landscape) (set-paper-size "a8"))
}

Note that this will only work with a _literal_ #f or #t as argument:
you'll likely want to have some actual condition evaluated at runtime,
like some variable name.  Then you'll need to write

#(define-macro (proc bool x y)
  `(if ,bool ,x ,y))

-- 
David Kastrup



reply via email to

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