koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Import koka code from elsewhere on your system through symlink #440

Closed chtenb closed 5 months ago

chtenb commented 5 months ago

Discussed in https://github.com/koka-lang/koka/discussions/439

Originally posted by **chtenb** January 17, 2024 Is it possible to import koka code from some other directory elsewhere on your file system? Using the `import` keyword with paths (relative or absolute) does not seem to work, at least on windows. I tried creating a symbolic link, which almost seems to work, but then still absolute paths end up in the kki file, like this: ``` module interface c:/Users/username/prj/kklib/util ``` with the error `prj_kklib_util.kki(1,19): error: invalid syntax`
daanx commented 5 months ago

I just pushed an initial fix for this (commit f58c61ff) (although we need to think a bit more about this in context of packages.). When loading a file that is either not relative to the include path roots, or has invalid directory names up-to the include path, in such case we only keep the declared module name in the source.

(However, that also means the compiler cannot find such modules unless referred to relatively since the connection to the file path is broken -- however, I think this is not a problem in practice since loading such files can only be done explicitly by the user anyways. )