lilypond-user
[Top][All Lists]
Advanced

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

Re: bookparts


From: Flaming Hakama by Elaine
Subject: Re: bookparts
Date: Mon, 5 Mar 2018 16:30:17 -0800


From: David Kastrup <address@hidden>
To: Wols Lists <address@hidden>
Subject: Re: bookparts
Wols Lists <address@hidden> writes:

> On 05/03/18 17:55, Kieren MacMillan wrote:
>> Hi Knut,
>>
>>> Because the definition of testing is invalid at that point of the main
>>> source file. If tempTest.ly would contain e.g. a score or a \paper block
>>> no error would occur.
>>
>> No, it still throws an error because you can't define a variable
>> inside a \bookpart (which is what \include-ing it at that point
>> does).
>>
> And as a programmer, I think "scope". You are defining the variable
> where you want to use it.

That's not what "scope" means.

Well, it's kind of what it means:  if you have different scopes,
then you can define variables in whatever scope is appropriate.

As best practice, you generally define variables in the most local
scope that is practicable, to avoid "polluting" the bigger namespaces.
So, "defining the variable where you need it" is, in practice, what
you do when you have different scopes available.

I'd add that, if there is no scoping, then that would mean that
there is only one scope.  In which case, it wouldn't matter where
you defined something, since defining anything anywhere makes
if available everywhere. 

Without scopes, you can still usually "define the variable where
you need it" (although that would not be best practice since it is
usually best to define all variables in use at the top of the scope.)

 
> It's widely accepted that that is good practice, global variables lead
> to errors, mistakes and confusion. But here you are forced to declare
> your variables at the global level :-(

Bookparts at global level are collected into an implicit book.  If books
have a scope of their own, no "global" definitions would be visible in
explicit books since they would be separate from the scope in the
implicit book.


This is a bit confusing since it seems that
you are saying 2 things:

     1) If books have a scope of their own, [scopes of explicit books would be]
    separate from the scope in the implicit book.

This makes sense, since we'd expect the scopes of books,
which are siblings, to be distinct.

But, I don't think that the issue was to use definitions
from one book in another book.   The issue was:
how do I define variables within a book, to be used
within that same book.


However, I don't understand:

    2) If books have a scope of their own,
no "global" definitions would be visible in
explicit books


I'd rather expect that any book scope
would be within the global scope,
so anything defined globally
would be available within each book.


 
Unfortunately, there does not appear to be a concept readily consistent
with scoping the current book/bookpart design.  Because "scope" does not
mean "you are defining the variable where you want to use it".  A
consequence of well-defined scopes is that you can more often do it in
that manner without impacting other code.  But I haven't seen a good
"well-definition" with LilyPond.  I am pretty sure that people would
protest books not getting to see definitions made "outside" of them.  So
normal books would have to be nested in the implicit default book like
bookparts of the implicit book are.

This seems backwards from the discussion earlier,
where the advice was to import your files with variables
into the global space, not within the bookpart.





David Elaine Alt
415 . 341 .4954                                           "Confusion is highly underrated"
address@hidden
skype: flaming_hakama
Producer ~ Composer ~ Instrumentalist
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


reply via email to

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