Skip to content
This repository has been archived by the owner on Jul 23, 2022. It is now read-only.

Can’t require pollen/setup for syntax #229

Closed
otherjoel opened this issue Jul 3, 2020 · 10 comments
Closed

Can’t require pollen/setup for syntax #229

otherjoel opened this issue Jul 3, 2020 · 10 comments

Comments

@otherjoel
Copy link
Contributor

otherjoel commented Jul 3, 2020

Under Racket BC 7.7/Pollen 3.1.2526.1362, running this in a file saved as pollen.rkt:

#lang racket
(require (for-syntax pollen/setup))

Produces this error:

pollen/setup: defective `setup` submodule in "/Users/joel/Documents/code/sandbox/pollen.rkt"
pollen/setup: defective `setup` submodule in "/Users/joel/Documents/code/sandbox/pollen.rkt"
standard-module-name-resolver: cycle in loading
  at path: /Users/joel/Documents/code/sandbox/pollen.rkt
  paths:
   /Users/joel/Documents/code/sandbox/pollen.rkt

This used to work, and doesn’t anymore. But I actually can’t figure out why it used to work.

@mbutterick
Copy link
Owner

As with #228, I think this is another error that was formerly suppressed, now revealed. Whenever pollen/setup is loaded, it needs to resolve certain values by looking inside pollen.rkt. So off the top of my head, it seems like what you’re trying to do should cause an error, because indeed it is a cycle in loading.

Still — what are you trying to accomplish by doing (require (for-syntax pollen/setup))? Maybe there’s a workaround. Or maybe the failure should be allowed in this case.

@otherjoel
Copy link
Contributor Author

Still — what are you trying to accomplish by doing (require (for-syntax pollen/setup))?

I’ve been doing this in support of a macro for defining tag functions that branch to other functions automatically depending on current-poly-target. (The macro itself references setup:poly-targets.)

@otherjoel
Copy link
Contributor Author

As with #228, I think this is another error that was formerly suppressed, now revealed. Whenever pollen/setup is loaded, it needs to resolve certain values by looking inside pollen.rkt. So off the top of my head, it seems like what you’re trying to do should cause an error, because indeed it is a cycle in loading.

This is what I thought, too. The weird thing is though, I am pretty sure the macro used to work as expected: if I changed (define poly-targets '(html)) to (define poly-targets '(html pdf)) inside my pollen.rkt setup module, I would start getting errors about pdf-tagname being an unbound identifier (because I hadn’t written those functions yet). If in older versions of Pollen there was an exception being suppressed, wouldn't it fall back on the default value and never include 'pdf in setup:poly-targets?

@mbutterick
Copy link
Owner

When I reset to commit 67c0c95 (before pollen/setup became more strict) and run this pollen.rkt:

#lang racket
(require (for-syntax pollen/setup))

(begin-for-syntax
  (println (setup:poly-targets)))

(module setup racket/base
  (provide (all-defined-out))
  (define poly-targets '(html pdf txt)))

The result I get is '(html) (the default value) not '(html pdf txt).

@otherjoel
Copy link
Contributor Author

It does seem in principle like you might end up having to say “you just can’t use macros in pollen.rkt that depend on pollen/setup in phase 1”. If that were the case, it would be a mild bummer. Maybe the workaround in this case would be just to define the list of output formats outside my setup module, or define it in two separate places and keep them in sync manually.

@mbutterick
Copy link
Owner

Right: you could define poly-targets in an external file, let’s say "exts.rkt":

#lang racket
(provide (all-defined-out))
(define poly-targets '(html pdf txt))

Then in your "pollen.rkt", you could import it twice, making the value available in both places:

#lang racket
(require pollen/setup (for-syntax "exts.rkt"))

(module setup racket/base
  (provide (all-defined-out))
  (require (prefix-in ext: "exts.rkt"))
  (define poly-targets ext:poly-targets))

Thereby breaking the loading cycle.

@otherjoel
Copy link
Contributor Author

Thanks, I will take that route!

@oldmankit
Copy link

I think this means the fourth pollen tutorial (on poly output targets) is currently broken.

#lang racket/base
(require racket/date txexpr pollen/setup)
(provide (all-defined-out))
 
(module setup racket/base
(provide (all-defined-out))
(define poly-targets '(html txt ltx)))

When I paste that as-is into Dr Racket, it gives the defective setup submodule error.

@mbutterick
Copy link
Owner

That file shouldn’t produce an error (and doesn’t, for me). Try deleting any neighboring compiled directories to make sure Racket isn’t getting confused.

@oldmankit
Copy link

That file shouldn’t produce an error (and doesn’t, for me). Try deleting any neighboring compiled directories to make sure Racket isn’t getting confused.

Hmmm, well you're right, I'm having no problem re-testing it today. I'm not sure what's changed, but it could well be that I've removed compiled directories which has fixed it.

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants