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: Thomas Morley
Subject: Re: Procedure for set-paper-size in \paper ?
Date: Sat, 19 May 2018 15:53:03 +0200

2018-05-19 9:45 GMT+02:00 David Kastrup <address@hidden>:
> 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.

Uh, oh, another typo/oversight.
Note to self: Don't post anything while being overtired...

>
> 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

Thanks for the insights,
  Harm



reply via email to

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