Arc Forumnew | comments | leaders | submitlogin
1 point by rocketnia 5092 days ago | link | parent

I could be wrong, but I think there's no widely adopted way to do those things, even in Anarki. I think most people just use a rather shallow directory structure and spell out (load "lib/something.arc") every time. Note that (load "...") resolves the path relative to Racket's (current-directory), which is usually the working directory Racket was started under. So typically people just start Racket from their Arc directory and don't bother messing with environment variables.

That doesn't mean it's a good situation here. :-p In particular, if someone ever wants to use multiple versions of the same library with the same Arc installation (loading them conditionally, maybe), I think the library'll need to be internally location-agnostic; you can't just put both versions in the same directory, after all. ^_^

So in Lathe I go to some trouble to make an alternative 'load function, 'loadrel, just so I can keep track of the current directory. It uses a global variable, 'load-dir* , to keep track of the current file's directory, and that variable is maintained by the functions 'loadrel and 'loadfromwd ("load from working directory," merely a 'load-dir* aware version of Arc's regular 'load).

If you want to try out my code, the necessary definitions are 'loadval from arc/modules/modulemisc.arc and 'split-at-dir, 'normalize-path, 'load-dir* , 'loadfromwd, and 'loadrel from arc/modules/path.arc. It's probably easier just to load the whole Lathe module system, which 'loadrel is a part of:

  (= lathe-dir* "lib/lathe/")
  (load:+ lathe-dir* "loadfirst.arc")
However, I'm noticing that the code's a bit more buggy than I'd like. XD In particular, I've got to fix this right away:

  arc> (normalize-path "a//c/../b.arc")  ; correct
  a/b.arc
  arc> (normalize-path "a.arc")  ; incorrect
  a.arc/
If you're going to implement something like this yourself, I recommend dropping to Racket and using Racket paths to avoid the trouble of things like my 'normalize-path. For a more comprehensive treatment, maybe someone could patch 'load to interact with Racket's 'current-load-relative-directory? Would that even make sense?