lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme help request: How can else of an if-statement be made to do n


From: Aaron Hill
Subject: Re: Scheme help request: How can else of an if-statement be made to do nothing?
Date: Fri, 11 Dec 2020 12:54:26 -0800
User-agent: Roundcube Webmail/1.4.9

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

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