The module search path on Winidows XP

For the Compleat Fan
Locked
ssqq
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

The module search path on Winidows XP

Post by ssqq »

When I use with newlisp-GS:

Code: Select all

(load "module-xxx.lsp")
on WIndows xp, Only valid path is $HOME.

Could I set many directory to load module without prefix directory name?

ryuo
Posts: 43
Joined: Wed May 21, 2014 4:40 pm

Re: The module search path on Winidows XP

Post by ryuo »

According to the documentation, there appears to be only a single directory from which modules are loaded by default. The environment variable "NEWLISPDIR" is used for this purpose. It appears to me that, if you want to load it from "many directories", you will need to implement it yourself. There appears to be no builtin function to load from more than one directory. If you have ever used C, this is like having to tell the compiler where to find additional headers. Now. for some possible solutions:

1) You can append the additional directories to the "NEWLISPDIR" environment variable, using a ":" or another character to separate the directories. You can then redefine the "module" function to search through every directory in the "NEWLISPDIR" environment variable. And then you can load the first module file you find under these directories. This solution uses the same approach that POSIX / UNIX uses to find binaries, but in this case you are looking for module files instead of binaries.

2) You can define a function for every directory you wish to load a module file from. I would not call this ideal, because the first solution provides a single function for all the directories you want to load module files from.

You can read up more about how this works by reading the relevant documentation section here:

http://www.newlisp.org/downloads/newlis ... em_symbols

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: The module search path on Winidows XP

Post by rickyboy »

ssqq wrote:When I use with newlisp-GS:

Code: Select all

(load "module-xxx.lsp")
on WIndows xp, Only valid path is $HOME.

Could I set many directory to load module without prefix directory name?
When given a relative pathname (as in your example: "module-xxx.lsp"), load will assume that it is based upon the current working directory (WD). If you didn't change the WD in newlisp, then the WD is the one that was current when you launched newlisp. In your case, you probably started newlisp when your current WD was $HOME. That's why saying (load "module-xxx.lsp"), in your case, was equivalent to (load (append (env "HOME") "/" "module-xxx.lsp")).

And since the expression (real-path) evaluates to the current WD -- expressed as a string -- in general, (load "module-xxx.lsp") is equivalent to (load (append (real-path) "/" "module-xxx.lsp")).

Using load with an argument that is a relative pathname is usually what one wants. However, you can use an absolute pathname with load.

ryuo is correct that there is no primitive procedure to load a file that is on some kind of a "path" (like the (standard) PATH environment variable). As ryuo said, you could write one yourself. However, I'd recommend not using the NEWLISPDIR environment variable for this "path", as at least one newLISP standard procedure uses it, namely module. Just choose another one.

Happy hacking!
(λx. x x) (λx. x x)

Locked