picrin icon indicating copy to clipboard operation
picrin copied to clipboard

import sld files

Open sethalves opened this issue 11 years ago • 2 comments

I would like to be able to import libraries from .sld files (files which contain (define-library at the top level). I would also like to have some control over the search path and possibly over the file extension.

sethalves avatar Jun 17 '14 17:06 sethalves

@sethalves

That's the thing I'm thinking of right now. We've not yet done automatic path search on library imports because there's an ambiguous point that how to determine the root path from which we begin searching for .sld files. If you have foo/bar.sld both on the system and on the current directory, when you run (import (foo bar)), what will (or must) happen? I'm not pretty sure which is the 'right' behavior. And what is worse is R7RS doesn't mention this at all.

One solution is that completely split the 'loading' phase and the 'import' phase, which we'd chosen to go so far. This is really simple and Common Lisp and some of major scheme implementations also take this way. A bad point is you always need to require what you want to use, which is the thing you pointed out.

Another is introducing certain rules for file resolution on library import. The most famous programming language that I know goes this way is Java (maybe the second is Haskell GHC). We have to assure what kind of rules should fit the practical uses and are scalable.

IMO, the first option is better for us. Unlike Java or Haskell, our implementation permits top level expressions have side effects such as printing or destructive operations, and this means that when to load and how many times to load often matter. Such property doesn't match with Java-like import style. I remember OCaml takes this style although it allow side effects on top level, but I'm not very familiar with it.

Anyway, I think there are many things to be solved remained. It appears yeah an easy task at a glance, but is so difficult a problem in fact...

nyuichi avatar Jun 18 '14 01:06 nyuichi

Chicken's r7rs library support currently requires that it see define-library (either directly in the source or due to an include or inclub) before the import. It can be annoying to get the includes in the right order, but it does dodge load path issues.

Chibi has a default load path which you can append or prepend to (with command-line switches), and/or set (or clear) with an environment variable. Chibi insists that the file end in .sld (I think? maybe an option was added to adjust this).

Gauche allows you to manipulate load-suffix and load-path directly, so I end up with things like:

#! /bin/sh #| -- scheme -- exec gosh
-e '(append! load-suffixes (list ".sld"))'
-e '(append! load-path (list "."))'
-ftest -r7 $0 "$@" |#

Sagittarius has command line switches for appending and prepending to the load path and the list of suffixes to check for. I can never remember which is the outer loop.

I think Foment just searches from the user's current-working-directory. It looks for a .sld file and then a .scm file. I suspect a command-line switch to adjust the load-path will be added soon.

sethalves avatar Jun 18 '14 04:06 sethalves