This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

importing module from source files


I just checked in the last feature planned for Kawa 2.0:
Being to import a library from a source file.

If you import a library:
  (import (foo bar))
you can specify an explicit source path:
  (import foo bar "libraries/foo/bar.scm"))

If you don't specify an explicit source path,
you get an *implicit* source path "foo/bar.scm".

A source file can contain multiple define-library forms.
It can also contain top-level definitions and expressions, but there are
some restrictions on that.

You can specify a search path, which is a list of strings.
See the getImportSearchPath method in ImportFromLibrary.java.

The default search path ["."].  Note that a relative path like ".'
is not relative to the current file or the current directory,
but to the current root.  If the current source file (the one
containing the import) is class "a.b.c" in class "/my/classes/a/b/c.scm"
then the "." in the search path resolves to "/my/classes".
Thus we look for "/my/classes/foo/bar.scm"
or "/my/classes/libraries/foo/bar.scm if there an explicit path
"libraries/foo/bar.scm".

A string in the search path can also be a pattern, which has the
form "<x y>PATH/*.EXT"  This only matches if the imported library
name *starts with* (x y).  Then the asterisk "*" is replaced
by the rest of the implicit path - without the extension.

For example:
  (import (x y z w "path.scm"))
The "path.scm" is ignored when matching against a pattern.
Instead we match (x y z w) against (x y) - which matches.
The "*" is replaced by "z/w" we we get "PATH/z/w.EXT".
(This allows you to match with a non-default extension - for example
some Scheme implementation use ".sld" for libraries.)

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.

Please try out this new functionality.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]