[plt-scheme] Bytecode compiled file location

From: Daniel Pinto de Mello e Silva (daniel.silva at gmail.com)
Date: Sun Jan 30 20:56:57 EST 2005

On Mon, 31 Jan 2005 01:05:22 +0000, Matthew Jadud <mcj4 at kent.ac.uk> wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> I read the thread on how a script might be told where it is. Is there
> any way to create a bytecode-compiled executable that knows where it is?
> That is, it would have access to the location of it's own executable
> file path?
> 

Well, you can use current-load-relative-directory when loading zo
files that aren't modules:

/tmp/foo $ cat hidden.scm
(printf "I'm not a module.~n")
(printf "Load-relative path: ~a~n"
        (current-load-relative-directory))
/tmp/foo $ mzscheme
Welcome to MzScheme version 299.22, Copyright (c) 2004 PLT Scheme, Inc.
> (require (lib "compile.ss"))
> (compile-file "notmod.scm")
> (load/use-compiled "notmod.scm")
I'm not a module.
Load-relative path: /tmp/foo
>
/tmp/foo $ cd..
/tmp $ mv foo bah
/tmp $ cd bah
/tmp/bah $ mv notmod.scm hidden.scm
/tmp/bah $ mzscheme
Welcome to MzScheme version 299.22, Copyright (c) 2004 PLT Scheme, Inc.
> (load/use-compiled "notmod.scm")
I'm not a module.
Load-relative path: /tmp/bah
>

But the parameter doesn't seem to be set when
(requiring?/instantiating?) modules...

/tmp/foo $ cat foo.ss
(module foo mzscheme
        (require (lib "etc.ss"))

        (printf "Loading foo from ~a~n"
                (this-expression-source-directory))

        (printf "The load-relative path is ~a~n"
                (current-load-relative-directory)))
/tmp/foo $ mzscheme
Welcome to MzScheme version 299.22, Copyright (c) 2004 PLT Scheme, Inc.
> (require (lib "compile.ss"))
> (compile-file "foo.ss")
> (require "foo.ss")
Loading foo from /tmp/foo
The load-relative path is #f
>
/tmp/foo $ cd..
/tmp $ mv foo bah
/tmp $ cd bah
/tmp/bah $ mv foo.ss hidden.ss
/tmp/bah $ mzscheme
Welcome to MzScheme version 299.22, Copyright (c) 2004 PLT Scheme, Inc.
> (require "foo.ss")
Loading foo from /tmp/foo
The load-relative path is #f
>

Although you can set it and dynamic-require the module:

/tmp/bah$ mzscheme
Welcome to MzScheme version 299.22, Copyright (c) 2004 PLT Scheme, Inc.
> (parameterize ([current-load-relative-directory "/tmp/bah"])
    (dynamic-require "foo.ss" #f))
Loading foo from /tmp/foo
The load-relative path is /tmp/bah
>


Daniel



Posted on the users mailing list.