[plt-scheme] Bytecode compiled file location
You might also find useful stuff in the definition of
this-expression-source-directory.
Robby
On Jan 30, 2005, at 7:56 PM, Daniel Pinto de Mello e Silva wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> 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
>
>