guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modules


From: Neil Jerram
Subject: Re: Modules
Date: Sat, 29 Jan 2011 13:08:29 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Marek Kubica <address@hidden> writes:

> What about "the same directory that the file is in"? The point is, when
> writing scripts that become larger than one file, splitting them into
> modules becomes immensely painful because the modules cannot find each
> other.

I agree that this is a bit awkward.  My current solution is

(load "setup-load-path.scm")

at the start of each top-level script - which relies on the fact that
`load' will look in the same directory as the script file - with
setup-load-path.scm containing:

(cond-expand (guile-2
              (eval-when (load compile)
                         (let* ((bindir (dirname (car (command-line))))
                                (absdir (cond ((string=? bindir ".")
                                               (getcwd))
                                              ((string-match "^/" bindir)
                                               bindir)
                                              (else
                                               (in-vicinity (getcwd) bindir)))))
                           (set! %load-path (cons (in-vicinity absdir "..")
                                                  %load-path)))))
             (else
              (let* ((bindir (dirname (car (command-line))))
                     (absdir (cond ((string=? bindir ".")
                                    (getcwd))
                                   ((string-match "^/" bindir)
                                    bindir)
                                   (else
                                    (in-vicinity (getcwd) bindir)))))
                (set! %load-path (cons (in-vicinity absdir "..")
                                       %load-path)))))

This has the effect of adding the parent of the script-containing
directory to the load path.

Part of the complexity is supporting both 1.8 and 1.9/2.0.  For 1.9/2.0
support only, I believe it could be simplified by changing `load' to
`include', and retaining only the body of the `eval-when'.

Regards,
        Neil



reply via email to

[Prev in Thread] Current Thread [Next in Thread]