[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Understanding scope of functions in Scheme modules
From: |
Urs Liska |
Subject: |
Re: Understanding scope of functions in Scheme modules |
Date: |
Sat, 25 Jul 2020 22:25:19 +0200 |
User-agent: |
Evolution 3.36.4-1 |
I thought I had a good idea, but it got me into hot water, with no
border in sight yet...
I thought I could do the following:
* Define-public my "internal" procedures in a module _my-module
* Use that module in my-module
All the stuff defined in _my-module will be visible in my-module, and
all the stuff defined publicly in my-module will be seen in later
LilyPond files. If some later Scheme module needs access to it it can
use my-module.
While I have the impression this actually works I run into situations I
wouldn't have expected. Unfortunately I can't really provide an MWE for
it.
But could someone give me a hint how I can bring myself in a situation
to get
Unbound variable: define-void-function
?
This is defined in music-functions.scm, and it should in any case have
been loaded before I ever issue an \include "oll-core/package.ily",
isn't it?
Probably the real issue is totally somewhere else, but I just have to
shoot in the dark here, hoping for some reflections ...
BestUrs
Am Samstag, den 25.07.2020, 10:28 +0200 schrieb Urs Liska:
> Hi,
>
> I'm trying to clean up some code in openLilyLib, most of which had
> been
> added when I was just starting to understand the topics I had to deal
> with at any point ...
>
> One thing I'm right now struggling with and that I'd like to get
> right
> this time is the scoping of code within Scheme modules.
>
> My observation at this point seems to be:
>
> * I can define procedures or variables in a Scheme module
> equivalently
> with (define-public my-proc) or (define my-proc) (export my-proc)
> * I can include such a module in a .ly file with (use-modules (my-
> module)) (if it's in the Guile path).
> * my-proc will then be available for any later LilyPond code (i.e.
> also in other files that are later in that compilation's parsing)
> * my-proc will *not* be available in other .scm files, in these I
> would have to explicitly include my-module with use-modules.
>
> Is this correct so far?
> If so is there a way to make names from modules only available within
> the LilyPond file that uses the module?
>
> I would like to have more encapsulation, so that the helper functions
> needed for the implementation are only visible where needed to have
> less clutter in the global namespace, like in many other languages
> where you have to explicitly import modules you want to use within
> each
> file.
>
> I think it will already be progress just to have the code *organized*
> like that, the camelCase-d user-facing LilyPond functions in the .ily
> file and the Scheme-define-d helper code in a separate .scm file. But
> if there were a way for real scoping it would be better.
>
> Any suggestions available?
>
> Thanks
> Urs
>
>