guile-user
[Top][All Lists]
Advanced

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

Re: How to correctly load modules from runtime defineable locations?


From: Zelphir Kaltstahl
Subject: Re: How to correctly load modules from runtime defineable locations?
Date: Fri, 6 Mar 2020 21:11:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

Hi!

I don't know about other ways, but using the -L argument, you can run
Guile programs from anywhere, because it will have the effect of making
it look to Guile as if it was started from that -L specified path.

Using `add-to-load-path` would be in your code, but usually I think one
should prefer to keep such things out of the code. I guess a shell
script would be better even, than using `add-to-load-path`.

However, this is only my opinion and I am myself not sure, whether that
is the best way.

I always use the -L argument when running tests, which are in a parallel
directory hierarchy to the source code. I specify a path that points to
a directory, which is (grand* …)parent of both, the tests directory and
the source code directory. Only then my tests have access to the modules
defined in the source code and can use `use-modules` as I described.

Regards,
Zelphir

On 3/6/20 5:29 PM, Михаил Бахтерев wrote:
> Thanks for the detailed answer.
>
> When i run
>
>   guile -L lib bin/check.scm
>
> everything works fine. No warnings.
>
> But my problem is that client wants just to unpack code archive to the
> random location and run it from there. Unfortunately, no GUIX, no custom
> builds. I don't understand what is the difference between -L option and
> add-to-load-path. It seems, that -L just adds lib directory to the
> %load-path, and that is it.
>
> May be it would be better to provide shell script, but i would like
> to solve this in pure Guile, if possible. May be, instead of
> adding-to-load-path, the better solution would be to reexecute Guile
> with appropriate -L options from simple trampoline .scm script?
>
> If i opt to this solution of reexecuting Guile, are there better and
> more robust choices than passing options through command line? Could the
> passing paths through environment variables be more reliable option?
>
> On Fri, Mar 06, 2020 at 12:53:37PM +0100, Zelphir Kaltstahl wrote:
>> Hi!
>>
>> I am not sure this will help you, but here is what I observed and what
>> works best for me:
>>
>>   * For running Guile programs use: `guile -L <root dir of project>
>>     <path to scm file>`.
>>   * For using libraries:
>>       o If Guile is installed via GUIX, try to install the library
>>         through GUIX as well, then it should be available for Guile.
>>       o If Guile is installed via GUIX, but the library is not on GUIX
>>         or not in the version you would like, create a directory
>>         somewhere and set the Guile load path for that directory.
>>       o If Guile is built and installed by yourself also use Guile load
>>         path.
>>   * Modules need to be named the same as the directories they are in to
>>     be found:
>>       o To use (use-modules (some mymodule)) the module should be in a
>>         directory `some` and a file `mymodule.scm`.
>>       o To use (use-modules (some)), the module should be in a file
>>         named `some.scm`.
>>
>> Perhaps the Guile load path varies on different systems?
>>
>> Regards,
>> Zelphir
>>
>



reply via email to

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