On 2018-05-18 14:24, Thomas Morley wrote:
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.
(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"))
}
\score { { R1 } \layout { ragged-right = ##f } }
Paper-size is always a8-landscape.
(3)
Trying:
#(define (proc bool x y)
(if bool x y))
\paper {
#(apply set-paper-size (proc #t '("a8" 'landscape) '("a8")))
}
\score { { R1 } \layout { ragged-right = ##f } }
Paper-size is always a8
---------
What's happening here and why?
And how to make a procedure accepting set-paper-size work, with
different settings and an if-condition?
My Scheme is a little rusty over the years, but I will try to explain
what is going on.
Firstly, `if` has a rule that it only evaluates either the true-value or
false-value based on the Boolean. That means exactly one of the two
expressions will evaluate.
Your `proc` function does not have this behavior, as the arguments
passed in will be evaluated before you get to the inner `if`. Now,
`set-paper-size` has a side-effect, so the evaluation of that function
alone is enough to have an impact. Technically, the function should be
named `set-paper-size!`, as the convention is to suffix an exclamation
to indicate such functions.
So, calling `proc` with the two functions results in both being
evaluated, which is not what you want.
Your `apply` approach is closer to what you want, since you are using
`proc` as a means of selecting the arguments you want and calling
`set-paper-size` only once. This should work, except you have an extra
quote.
%%%%
#(apply set-paper-size (proc #t '("a8" landscape) '("a8")))
%%%%
The outer quote for invoking the list shorthand already results in
`landscape` being a symbol. The extra quote would put another layer of
indirection, which `set-paper-size` does not expect.
Hope this helps,
-- Aaron Hill
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user