lilypond-devel
[Top][All Lists]
Advanced

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

Re: Solution for including a file only once


From: Hans Aberg
Subject: Re: Solution for including a file only once
Date: Thu, 11 Feb 2010 12:48:28 +0100

On 7 Feb 2010, at 04:51, Michael J. O'Donnell wrote:

I *think* that I have the essential solution to include a file exactly
once, no matter how many times it is mentioned. That is, with the
following definition,

   \includeIfAbsent "MyFile.ly"

should copy in MyFile.ly, just as though you had written

   \include "MyFile.ly"

unless an inclusion (either through \include or through
\includeIfAbsent) has already started (and usually finished). If there
is a circular path of \includes, LilyPond appears to enter an infinite
loop, but \includeAbsent will break a cycle. That's why it's important
that I said "unless an inclusion ... has already *started*," rather than
"already happened."

The sweat here involved avoiding any preparatory code to enable the
mechanism. You need nothing more than the definition of includeIfAbsent.

I'm not sure how either \include or \includeIfAbsent behave inside a
context. It's probably not a good idea to use either one except at the
outermost level---inner stuff should usually be done with variables.
But, it would be cool if someone tested the possibility.

The Haskell functional language <http://haskell.org> has a module system. The command that ensures that a module is loaded only once is called "import".

One can only use "import" at the beginning of a file. So it is not possible to appear inside code.

There are some other things attached to the module system:

It defines a name-space, like namespace in C++. So
  module Foo

  ...
  f = ...
causes that actual name of f to be Foo.f. If one imports a name f form a module Bar, then one has both Foo.f and Bar.f present. If one wants to use the name for one of them, one needs to have system for disambiguation.

In addition, a module can decide which names to export: all or just some of them, creating a user interface. Though the syntax in Haskell is just (...) after the module name, here write
  export f
Then f can be use, not not other names not in the list.

  Hans






reply via email to

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