This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: importing module from source files
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Wed, 19 Nov 2014 13:38:32 -0500
- Subject: Re: importing module from source files
- Authentication-results: sourceware.org; auth=none
- References: <546AB750 dot 7010506 at bothner dot com>
On Nov 17, 2014, at 10:04 PM, Per Bothner <per@bothner.com> wrote:
> For now you can override the default search path with a property. E.g.
> kawa -Dkawa.import.path=".:/home/bothner/scm" my-script.scm
>
> I'm considering changing this to either:
> (1) Environment variable; or
> (2) a command-line variable assignment:
>
> http://www.gnu.org/software/kawa/Options.html#Options-for-setting-variables
>
> Not sure which is best.
> - Environment variables have various known problems - for one on Windows
> they're a little harder to set from the command line.
> - Java properties are standard on Java. However, the standard property-file
> system is quite horrible (at least for anyone who doesn't use Latin-1).
> They're also not portable across Scheme implementations - and can't
> be standardized.
> - The Kawa variable-setting feature only works for applications
> that invoke ApplicationMainSupport.processSetProperty - as kawa.repl does.
>
> I'm inclined to just use the kawa.import.path property as currently
> implemented, but feedback is welcome.
Maybe this is too complex, but I've solved this kind of problem in Java
by choosing option (3): all of the above.
Perhaps you could:
1. Check for a bound Scheme variable such as "kawa-import-path".
2. Fall back to Java property "kawa.import.path".
3. Fall back to environment variable "KAWA_IMPORT_PATH".
4. Default to ".".
Something like
(define (find-path pathname::String default::String)
(if (environment-bound? (interaction-environment) pathname)
(eval (string->symbol pathname) (interaction-environment))
(let* ((prop-name (pathname:replace "-" "."))
(prop (java.lang.System:getProperty prop-name)))
(if (not (eq? #!null prop))
prop
(let* ((env-name ((pathname:toUpperCase):replace "-" "_"))
(env-var (java.lang.System:getenv env-name)))
(if (not (eq? #!null env-var))
env-var
default))))))
(find-path "kawa-import-path" ".")
If you want to get really crazy, you could throw java.util.prefs.Preferences
in the mix -- I did that for an in-house application framework I wrote which
needed to have settings overridable in various combinations of per-user,
per-application, and per-machine.
--
Jamison Hope
The PTR Group
www.theptrgroup.com