mbutterick / pollen

book-publishing system [mirror of main repo at https://git.matthewbutterick.com/mbutterick/pollen]

Home Page:https://git.matthewbutterick.com/mbutterick/pollen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

define-runtime-path and pollen aren't cooperating properly

rfindler opened this issue · comments

This program:

#lang pollen
◊(require racket/runtime-path)
◊(define-runtime-path x "x")
◊(println x)

prints the path ..../pollen/private/x instead of the path to where the file is saved.

The problem seems to be that define-runtime-path relies on syntax-source-module, which is not pointing at the original source file. Do you know how to adjust this value? For instance, one can adjust the result of syntax-source by using syntax/loc. But syntax/loc doesn’t seem to affect syntax-source-module.

@AlexKnauth asked the same question on racket-users, though it went unanswered.

The confusing part is probably that syntax-source-module is based on scopes (or "lexical context" in the docs), not source location... because it seemed like that might be a good idea back when define-runtime-path was defined.

So, the answer to @AlexKnauth's question is

(define-syntax (macro stx)
  (syntax-parse stx
    [(_ name path-expr)
     (datum->syntax
      stx
      (syntax-e #'(define-runtime-path name path-expr))
      stx)]))

and I'll post that to the list.

Thanks, though that helps me see that my issue involves one more degree of complexity. My macro receives a list of syntax objects at the top level of a module and I don’t know which (if any) are define-runtime-path. Of course, define-runtime-path can only be at the top level of a module, so I suppose I could riffle through the list and apply this fix. That seems hacky — are there other forms like define-runtime-path that also need to be adjusted? — though if it’s necessary, I won’t worry about it.

Does your module-begin macro change the "lexical context" to be from some file in the pollen/private/ directory instead of the file they came from?

Oh: (replace-context #'here #'EXPRS)

(with-syntax ([EXPRS (replace-context #'here #'EXPRS)]

Yeah, I was futzing with that line and I still couldn’t make it work. But in the words of @mflatt, “It's probably just a matter of trying harder.”

Is there a reason the EXPRS are changed to the context of here, instead of certain other statements/bindings changed from here to stx or something?

Tried harder.

Thanks!

That was a fun one to watch