Hi Ian, Ian Hulin <i...@hulin.org.uk> 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