[plt-scheme] syntax/loc and this-expression-source-directory

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 7 08:53:07 EDT 2008

At Sun, 06 Apr 2008 14:36:33 -0400, Dave Herman wrote:
> My PLaneT package test.plt has a macro that extracts the directory of 
> the file containing a given expression:
>    (require (lib "etc.ss"))
>    (define-syntax (source-directory-of-expression stx)
>      (syntax-case stx ()
>        [(_ context)
>         (syntax/loc #'context
>           (this-expression-source-directory))]))
> This used to work but it isn't working in 3.99. That is, the following 
> module:
>    #lang scheme/base
>    (require (planet "test.ss" ("dherman" "test.plt" 1)))
>    (printf "~a~n" (source-directory-of-expression foo))
> prints the PLaneT directory where test.ss lives, rather than the 
> directory of the client module.
> I checked and the `syntax/loc' expression does have the correct 
> syntax-source information, so I imagine it must be some change to the 
> behavior of `this-expression-source-directory'? Is there a better way to 
> implement this macro?

Sometime between v350 and v370, `this-expression-source-directory'
changed to use the lexical context of a datum (when the context is from
a module).

I've changed `this-expression-source-directory' to accept a datum
"argument", so you can use it directly as


Posted on the users mailing list.