guile-devel
[Top][All Lists]
Advanced

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

Re: Trouble using (current-filename)


From: Neil Jerram
Subject: Re: Trouble using (current-filename)
Date: Tue, 21 Feb 2012 20:48:57 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Sorry for chipping in late to this discussion.

address@hidden (Ludovic Courtès) writes:

> I think it’s often undesirable.
>
> Suppose you want to use ‘current-filename’ in an ‘assert’ macro, for
> instance: what you want is a hint, not an absolute path, since that path
> is likely to be invalid at the time you see it (for instance, it could
> point to the source tree on a build machine of your distro.)

Or suppose that a script and accompanying module set is compiled in the
build tree, then installed or relocated elsewhere.  In this case, what
I'd be looking for, with this

 (add-to-load-path ...)

stuff, would be to discover the location of the running script file
_now_, and to construct a load path element relative to that.  If I'm
understanding correctly, 'current-filename' would give me the wrong
answer in that case too, because it would have the
pre-install/relocation location.

Perhaps after all the right thing, for my use case, is something based
on (car (command-line)) and (getcwd).  I currently have this
'compatibility definition' for Guile 1.8.x:

      (define (current-filename)
        (let* ((script (car (command-line)))
               (scriptdir (dirname script))
               (absdir (cond ((string=? scriptdir ".")
                              (getcwd))
                             ((string-match "^/" scriptdir)
                              scriptdir)
                             (else
                              (in-vicinity (getcwd) scriptdir)))))
          (in-vicinity scriptdir (basename script))))

But maybe that's the better solution for 2.x as well.

Regards,
      Neil



reply via email to

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