lilypond-user
[Top][All Lists]
Advanced

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

do it once in scheme if you include twice


From: Jan-Peter Voigt
Subject: do it once in scheme if you include twice
Date: Tue, 16 Nov 2010 14:07:37 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10

Hello folks,

I searched a little bit, to get something like the #ifndef stuff in a C-Header into some lily-files I include regularly.
Now I worked it out myself and I'd like to share it:

--snip--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% included from somewhere
#(if (not (defined? 'dostuff))(define-public dostuff #t))
% do something
#(if dostuff (define count 0))
#(if dostuff (set! count (+ count 1)))
#(if dostuff (define-public mystuff (list)))
#(if dostuff (display count))
#(if dostuff (display " Hello World\n"))
% set dostuff to false
#(set! dostuff #f)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% included again from somewhere
#(if (not (defined? 'dostuff))(define-public dostuff #t))
% do something
#(if dostuff (define count 0))
#(if dostuff (set! count (+ count 1)))
#(if dostuff (define-public mystuff (list)))
#(if dostuff (display count))
#(if dostuff (display " Hello World\n"))
% set dostuff to false
#(set! dostuff #f)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--snip--

In this example, "Hello World" will be displayed only once.
You need this, if you define a global function or a global list of items like my footnote-items (http://lsr.dsi.unimi.it/LSR/Item?id=728) and include the containing file more than once.

In fact, if you get into this situation, you also may rethink your file-organization ...

Stay tuned and have a good day!
Jan-Peter




reply via email to

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