guile-devel
[Top][All Lists]
Advanced

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

Re: add-relative-load-path ? - scm_add_load_path too?


From: Mark H Weaver
Subject: Re: add-relative-load-path ? - scm_add_load_path too?
Date: Tue, 31 Jan 2012 03:53:35 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Hi Ian,

Ian Hulin <address@hidden> writes:
> I've just seen the add-load-path scheme function in the new git
> documentation.
>
> Please, please, pretty please can we have a scm_add_load_path API
> equivalent callable from C/C++? The LilyPond initialization code
> currently does disgusting things like faking
> (eval (set! %load-path cons ( <blah> %load-path ) ) )

I took a look at the relevant Lilypond code:

  string s = "(set! %load-path (cons \"" + dir + "\" %load-path))";
  scm_c_eval_string (s.c_str ());

and indeed this isn't very nice.  I can suggest a couple of alternatives
that are much nicer.

Probably the easiest option here is to simply prepend the desired
directories onto the GUILE_LOAD_PATH environment variable before calling
scm_boot_guile.  Its contents will automatically be prepended to
%load-path during Guile initialiation.  The nice thing about this method
is that it will work with older versions of Guile as well, at least as
far back as Guile 1.4.

Barring that, the nicer (and more robust) way to prepend to any list is
as follows:

  SCM var = scm_c_lookup ("%load-path");
  scm_variable_set_x (var, scm_cons (scm_from_locale_string (dir),
                                     scm_variable_ref (var)));

Finally, although I don't recommend it in this case, if you really want
to build an expression to evaluate, it is much more robust to build list
structures instead of strings.  In this case:

  scm_primitive_eval
    (scm_list_3 (scm_from_locale_symbol ("set!"),
                 scm_from_locale_symbol ("%load-path"),
                 scm_list_3 (scm_from_locale_symbol ("cons"),
                             scm_from_locale_string (dir),
                             scm_from_locale_symbol ("%load-path"))));

All of these suggestions should work with Guile 1.8 as well as 2.0.x.
Hope this helps.

    Regards,
      Mark



reply via email to

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