Hello Aaron,

This makes sense, and the let statement is something I was missing (!)


mattfong

On Fri, Dec 11, 2020 at 12:54 PM Aaron Hill <lilyp...@hillvisions.com>
wrote:

> On 2020-12-11 12:30 pm, Matthew Fong wrote:
> > 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.
>
> Defining a variable would make sense if you needed the value in a few
> places, since that would cut down on redundant expressions.  But even if
> you only needed the value once, it sometimes makes sense to use
> variables to help keep other expressions simpler.  The \markup below is
> arguably easier to follow without the embedded Scheme expression:
>
> %%%%
> print-if-defined =
> #(define-void-function
>    (foo sym text)
>    ((boolean? #f) symbol? markup?)
>    (let ((color (if foo '(0.8 0.2 0.2) '(0.2 0.8 0.2))))
>     (if (defined? sym)
>         (add-text #{ \markup \with-color #color #text #}))))
>
> symA = "Something"
>
> \print-if-defined symB "Text"     % hidden
> \print-if-defined symA "Text"     % shown, green
> \print-if-defined ##t symA "Text" % shown, red
> %%%%
>
> NOTE: LilyPond's parser is able to interpret "symA" as a symbol on its
> own without needing to escape to Scheme syntax by writing #'symA.  Just
> something to keep in mind as I think it results in cleaner usage.
>
>
> -- Aaron Hill
>

Reply via email to