Arc Forumnew | comments | leaders | submitlogin
How are the libs in lib/ intended to be loaded?
4 points by zck 2384 days ago | 3 comments
There are 49 files in Anarki's lib/ folder. 18 of them are loaded by libs.arc, which is loaded in boot.scm.

But that means there are 31 extra lib files that aren't loaded by default. How are they expected to get loaded?

Anarki doesn't seem to `cd` to its own directory, so I can't just call `(load "lib/files.arc")`. How do I load these extra libraries?



4 points by rocketnia 2354 days ago | link

I've always been frustrated with Arc's lack of a standard practice for loading dependencies (although I suppose akkartik might consider that a feature ^_^ ).

If the way Arc's lib/ directory has been used is any indication, the way to do it is:

- Start in the Arc directory when you run Arc, and never cd out of it.

- (load "lib/foo.arc"), or (require "lib/foo.arc") if you want to avoid running the same file multiple times

But I think for some Anarki users, the preferred technique has been somewhat different:

- Invoke Anarki from any directory.

- Ignore lib/ as much as possible. On occasion, load a library from there by using (load "path/to/arc/lib/foo.arc"), but a few libraries may make this difficult (e.g. if they need to load other libraries).

When I started writing Arc libraries, the first thing I wrote was a framework for keeping track of the location to load things relative to, so that my other libraries could load each other using relative paths regardless of which of the above techniques was in use. But the Lathe module system didn't catch on with anyone else. XD

More recently, eight years ago, rntz implemented the current-load-file* global variable that may make it easier for Anarki-specific libraries to compute the paths of the libraries they want to load. Nothing is currently using it in Anarki however.

-----

3 points by zck 2352 days ago | link

> - Start in the Arc directory when you run Arc, and never cd out of it.

Yeah, this makes sense if you're making something that only you use, but if I'm trying to make something a little more portable, like (as you mention) a library.

I'll have to look more into Lathe, and even current-load-file*.

-----

4 points by akkartik 2353 days ago | link

Whoa, I could have sworn I responded to this one :/

rocketnia is right that I tend to just run Arc from within its directory, keeping it alongside any Arc program I may be working on at the moment. As a result, I'd kinda always assumed you could run it from anywhere and find yourself in the Arc directory once you loaded up. Now I find this isn't the case:

  $ pwd
  /home/akkartik
  $ ./anarki/arc.sh
  arc> ($:current-directory)
  #<path:/home/akkartik>
This was initially surprising, but of course we're only parameterizing the current directory while loading libraries: https://github.com/arclanguage/anarki/blob/c3849efaf9/boot.s...

I'm not sure what to do about this. In addition to rocketnia's `current-load-file*` suggestion, should we just expose `arc-path` from boot.scm? I couldn't immediately see how to get to it from Arc.

-----