Hello Aaron, >.< Oh boy, that is *simple*. I went off the deep end on this, trying to make another variable that would get assigned the color. That clearly is not the way Scheme works. The inline conditional is a thing of beauty.
Looks like I need to spend more time studying Scheme syntax. Many thanks, mattfong On Fri, Dec 11, 2020 at 12:07 PM Aaron Hill <[email protected]> wrote: > On 2020-12-11 10:43 am, Matthew Fong wrote: > > Hello everyone, > > > > Resurrecting an old thread. I've been trying my hand in Scheme > > programming, > > via small examples on the project I'm working on. > > > > I wanted to extend the variable list to this function Harm wrote, to > > take > > an extra boolean variable, which is pretty trivial. The boolean is > > meant to > > change the color of the text depending if it's true or false. But I am > > not > > clear on how to define the color using the boolean. The trivial way to > > do > > it is adding a conditional under the first if, and duplicate all the > > code > > except the color. Is there a proper Scheme-ish way to do this? > > (Admittingly, I have not caught on to Scheme just yet -- my brain tends > > to > > work with Python) > > > > print-if-defined = > > #(define-void-function (sym text) (symbol? markup?) > > (if (defined? sym) > > (add-text #{ \markup \with-color #'(0.8 0.2 0.2) #text #}))) > > > > symA = "Something" > > > > \print-if-defined #'symB "Text" > > \print-if-defined #'symA "Text" > > Unless I am missing something from your specific use case, you should > only need to nest another (if ...) expression in place of the actual > color: > > %%%% > print-if-defined = > #(define-void-function (foo sym text) ((boolean? #f) symbol? markup?) > (if (defined? sym) > (add-text #{ \markup \with-color > #(if foo '(0.8 0.2 0.2) '(0.2 0.8 0.2)) > #text #}))) > > symA = "Something" > > \print-if-defined #'symB "Text" % hidden > \print-if-defined #'symA "Text" % shown, green > \print-if-defined ##t #'symA "Text" % shown, red > %%%% > > > -- Aaron Hill > >
