lilypond-user
[Top][All Lists]
Advanced

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

Re: Not Nice Review of the LilyPond


From: David Sumbler
Subject: Re: Not Nice Review of the LilyPond
Date: Sun, 02 Dec 2018 20:20:29 +0000

-----Original Message-----
From: address@hidden
To: David Sumbler <address@hidden>
CC: David Kastrup <address@hidden>, lilypond-user <address@hidden>
Subject: Re: Not Nice Review of the LilyPond
Date: Sun, 2 Dec 2018 14:17:11 -0500 (EST)

On Sun, 2 Dec 2018, David Sumbler wrote:
> > But MusiXTeX can do "if" statements.
> I felt that an "if" would be useful, so I eventually came up with:

That is useful for conditional includes, but it can't be embedded in
the
data structure that LilyPond calls "music" and stores in variables.  As
soon as something is turned into "music" it has to be data, not code;
conditionals must either be evaluated before the input is turned into
"music," or by separate code (usually, in Scheme rather than in
LilyPond
as such) that conditionally modifies the static "music."  That latter
approach, with tags in the "music" that can be filtered out, is what's
usually recommended as a substitute for real conditionals in LilyPond,
but
it's quite limiting compared to what programming languages can do with
"if."

For those familiar with programming languages it's not so mysterious
why
this situation comes about.  LilyPond takes care to call its variables
variables in the documentation.  You reference them; you don't execute
them.  They contain data, not code.  Obviously, data will be the same
every time you look at it, unless you externally change it.  But I wish
that without escaping to Scheme I could have something more like a
macro
than like a variable, evaluating its conditionals (and doing other
programming-language stuff) every time it is used.

*************

Well, I'm not quite sure what you are after but this works:

%%%%%%%%%%%%%%%
\version "2.19.81"

#(define (iffable? x)
  (or (string-or-music? x) (markup? x) (ly:score? x) (ly:book? x)))

iff = #(define-scheme-function
        ( flag var )
        ( boolean? iffable? )
        (if
         flag
         (if
          (string? var)
          (ly:parser-include-string var)
          var)))

partA = ##f

{ b4 b b b
  \iff \partA { g g g g }
  b1
}
%%%%%%%%%%%%%

Of course, that can be easily done with \tag; I just happen to like
\iff.  And the test need not be a single boolean: \iff (or var1 var2)
and other Scheme expressions will work too.

David




reply via email to

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