2018-05-19 9:45 GMT+02:00 David Kastrup <d...@gnu.org>:
> Thomas Morley <thomasmorle...@gmail.com> 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

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to