lilypond-devel
[Top][All Lists]
Advanced

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

Re: Macros


From: Erik Sandberg
Subject: Re: Macros
Date: Tue, 28 May 2002 10:09:56 +0200

> > a8 b
> > #ifdef scientific
> > c\footnote{..}
> > #else
> > cis
> > #endif
> > d
>
> Nothing is stopping you from using cpp for this now. Don't have to write
> a completely new preprocessor for this.

I know it IS possible, but:
- it requires that cpp is installed, which is non-trivial for non-programmers 
e.g. under windows.
- you would need to create your own build scripts, instead of just "ly2dvi 
score.ly"
- The syntax of cpp is not well suited for lilypond's needs. Just look at my 
example, it expands to 6 lines. \include does exist and seems to work as if 
it would be part of a preprocessor, so my feeling is that \ifdef, \define, 
etc. could be implemented in a similar way (but I haven't looked at the code 
so I don't know). A full cpp clone would of course be very much an 
overkill. The syntax could rather be something close to:

\define "GUITAR"
...
\instrument = \ifdef "GUITAR" "Guitar" \else "Cello" \endif
...
\notes{c \ifdef "GUITAR" c c \else c, c, \endif c}

Of course there might exist problems to implement this nicely & cleanly, so 
one alternative is to let if work more like C's ? operator, which would make 
it less flexible but cleaner, and it would change the last line to
\notes{c \ifdef "GUITAR" {c c} \else {c, c,} c}
i.e.
\define STRING 
would add STRING to some internal list of defined strings, while the music 
expression
\ifdef string musicexpr1 \else musicexpr2
would evaluate to musicexpr1 if string is found in this table, and musicexpr2 
otherwise. I guess this could be fairly easy to implement cleanly.

For my needs, this would work almost as fine as a pure preprocessor system, 
and it's a lot cleaner and simpler.

Erik



reply via email to

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