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

Closed
opened 5 years ago by rfindler · 11 comments
rfindler commented 5 years ago (Migrated from github.com)

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.

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.
mbutterick commented 5 years ago (Migrated from github.com)

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.

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`.
mbutterick commented 5 years ago (Migrated from github.com)

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

@AlexKnauth asked [the same question](https://groups.google.com/d/msg/racket-users/jhRmKkPTl-M/waaFsej3BAAJ) on `racket-users`, though it went unanswered.
mflatt commented 5 years ago (Migrated from github.com)

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.

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.
mbutterick commented 5 years ago (Migrated from github.com)

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.

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.
AlexKnauth commented 5 years ago (Migrated from github.com)

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?

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?
AlexKnauth commented 5 years ago (Migrated from github.com)

Oh: (replace-context #'here #'EXPRS)
014807df58/pollen/private/main-base.rkt (L38)

Oh: `(replace-context #'here #'EXPRS)` https://github.com/mbutterick/pollen/blob/014807df58ebfc99252934581ca65fedb0efda02/pollen/private/main-base.rkt#L38
mbutterick commented 5 years ago (Migrated from github.com)

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.”

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.”
AlexKnauth commented 5 years ago (Migrated from github.com)

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?

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?
mbutterick commented 5 years ago (Migrated from github.com)

Tried harder.

Tried harder.
rfindler commented 5 years ago (Migrated from github.com)

Thanks!

Thanks!
otherjoel commented 5 years ago (Migrated from github.com)

That was a fun one to watch

That was a fun one to watch
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen#202
Loading…
There is no content yet.