On Friday, August 31, 2018 at 11:11:29 PM UTC+8, Matthew Butterick wrote:
>
>
> On Aug 31, 2018, at 3:25 AM, Alex Harsanyi <alexha...@gmail.com 
> <javascript:>> wrote:
>
> Is there a way to write this macro such that the runtime path is defined
> relative to the location of the file that uses `define-sql-statement`?
>
>
> One option, using `syntax-source` to get the starting directory:
>
>
Unfortunately, this solution does not work.  The problem is that 
syntax-source returns an absolute path, so `define-runtime-path` will 
receive an absolute path as an argument.   This means that, even if a 
distribution is created, the path will still refer to the original file 
name inside the source tree, and if the distribution is moved to another 
computer, it will fail to find the file.  It is interesting however, that a 
copy of the file is present in the distribution directory, but this is not 
actually used when the program runs.

BTW, it took a long time to discover this problem, because I happen to run 
my "distributed" program on the same machine where I built it, and until 
last week, the exe in the distribution had access to the files in the 
source repository...

Alex. 


> #lang racket
> (require racket/runtime-path db (for-syntax racket/base))
>
> (define-syntax (define-sql-statement stx)
>   (syntax-case stx ()
>     [(_ name path)
>      (let-values ([(dir fn _) (split-path (syntax-source stx))])
>        (with-syntax ([dir (or dir 'same)])
>          #'(begin
>              (define-runtime-path rpath (build-path dir path))
>              (define name
>                (let ([vq #f])
>                  (lambda ()
>                    (unless vq
>                      (let ([s (call-with-input-file rpath port->string)])
>                        (set! vq (virtual-statement (lambda (_) s)))))
>                    vq))))))]))
>
> (provide define-sql-statement)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to