Using eval on a page causes rendering to fail #259

Closed
opened 1 year ago by jo-sm · 3 comments
jo-sm commented 1 year ago (Migrated from github.com)
Owner

I recently wrote a post on my website that involved evaluating some syntax to illustrate the expressiveness of Pollen:

#lang pollen

(define syx `(for/list ([i (in-range 1 10)]) 
    (* i 2)))

◊highlight['racket]{
(define syx `(for/list ([i (in-range 1 10)])
  (* i 2)))

(format "~a" syx)
(format "~a" (eval syx))
}

When I run it in start mode, everything seems to work and it's rendered as expected (first printing the syntax then printing the list). However, when I attempt to render the page using raco pollen render, I get the following error:

for/list: unbound identifier;
 also, no #%app syntax transformer is bound
  at: for/list
  in: (for/list ((i (in-range 1 10))) (* i 2))

  context...:
   body of (submod ".../src/posts/into-pollen.html.pm" pollen-module)
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/cache-utils.rkt:67:0: path->hash
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/cache-utils.rkt:124:2: generate-dest-file
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/file/cache.rkt:63:2: fetch-and-continue
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-val-first.rkt:555:3
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/cache-utils.rkt:114:0: cache-ref!
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/private/more-scheme.rkt:377:2: hash-ref!
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/cache.rkt:39:4: cached-require-base
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/render.rkt:430:2
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/render.rkt:460:2: cache-thunk
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/render.rkt:252:0: render-to-file-base
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-val-first.rkt:486:18
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/project-server-routes.rkt:292:0: route-default
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:375:33
   [repeats 1 more time]
   /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/web-server-lib/web-server/dispatchers/dispatch-servlets.rkt:63:2

I was able to work around this by evaluating it with (make-base-namespace):

(eval syx (make-base-namespace))

Is this intended, or is this a bug?


P.S. Since I don't have another place to put this, and sorry for putting this on a bug report: thanks for writing Pollen. I'm really happy to have a tool in Racket that lets me write my website, and more importantly a tool that is nice to use and just basically gets out of my way.

I recently wrote a post on my website that involved evaluating some syntax to illustrate the expressiveness of Pollen: ```racket #lang pollen ◊(define syx `(for/list ([i (in-range 1 10)]) (* i 2))) ◊highlight['racket]{ (define syx `(for/list ([i (in-range 1 10)]) (* i 2))) ◊(format "~a" syx) ◊(format "~a" (eval syx)) } ``` When I run it in `start` mode, everything seems to work and it's rendered as expected (first printing the syntax then printing the list). However, when I attempt to render the page using `raco pollen render`, I get the following error: ``` for/list: unbound identifier; also, no #%app syntax transformer is bound at: for/list in: (for/list ((i (in-range 1 10))) (* i 2)) context...: body of (submod ".../src/posts/into-pollen.html.pm" pollen-module) /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/cache-utils.rkt:67:0: path->hash /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/cache-utils.rkt:124:2: generate-dest-file /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/file/cache.rkt:63:2: fetch-and-continue /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-val-first.rkt:555:3 /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/cache-utils.rkt:114:0: cache-ref! /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/private/more-scheme.rkt:377:2: hash-ref! /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/cache.rkt:39:4: cached-require-base /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/render.rkt:430:2 /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/render.rkt:460:2: cache-thunk /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/render.rkt:252:0: render-to-file-base /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-val-first.rkt:486:18 /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/pollen/pollen/private/project-server-routes.rkt:292:0: route-default /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:375:33 [repeats 1 more time] /opt/homebrew/Cellar/minimal-racket/8.2/share/racket/pkgs/web-server-lib/web-server/dispatchers/dispatch-servlets.rkt:63:2 ``` I was able to work around this by evaluating it with `(make-base-namespace)`: ```racket (eval syx (make-base-namespace)) ``` Is this intended, or is this a bug? --- P.S. Since I don't have another place to put this, and sorry for putting this on a bug report: thanks for writing Pollen. I'm really happy to have a tool in Racket that lets me write my website, and more importantly a tool that is nice to use and just basically gets out of my way.
sorawee commented 1 year ago (Migrated from github.com)
Owner

I think this is a Racket question more than a Pollen question. The answer is, this is intended. See https://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29.

FWIW, Pollen has a discussion area at https://github.com/mbutterick/pollen-users.

I think this is a Racket question more than a Pollen question. The answer is, this is intended. See https://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29. FWIW, Pollen has a discussion area at https://github.com/mbutterick/pollen-users.
jo-sm commented 1 year ago (Migrated from github.com)
Owner

@sorawee After reading that I think I'm still a little confused. Like I mention, when the page is rendered via pollen start it renders fine, but not when rendered via pollen render. Is this because pollen start instantiates an initial namespace?

@sorawee After reading that I think I'm still a little confused. Like I mention, when the page is rendered via `pollen start` it renders fine, but not when rendered via `pollen render`. Is this because `pollen start` instantiates an initial namespace?
mbutterick commented 1 year ago (Migrated from github.com)
Owner

When using raco pollen start, every page render gets a fresh namespace (because this ensures that changes to the underlying files are reflected in the next refresh of the page). But during raco pollen render, all the renders share a namespace (because this is faster).

When using `raco pollen start`, every page render gets a fresh namespace (because this ensures that changes to the underlying files are reflected in the next refresh of the page). But during `raco pollen render`, all the renders share a namespace (because this is faster).
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

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