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:
>

Hi Matthew, 

Thanks for this solution, it works.  While I understand what is being done, 
I do not understand why it is necessary....

Another interesting thing is that, with my original macro, when running the 
code using racket, the file path had to be relative to the file containing 
the definition, but when creating an executable using raco exe, the file 
path had to be relative to the file using the macro.  Your solution works 
in both cases.

Best Regards,
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