Wondering if MB/anyone can help me understand this problem I'm having. I
got pretty far but I think I've hit a wall.
A bit of setup: When dealing with multiple output formats you write a lot
of tag functions of the form:
; In pollen.rkt
(define (bold elems)
(case (current-poly-target)
[(pdf) (pdf output here)
[else (html output here)]))
Instead of doing all this, I'd like to automatically split the
implementation for each target format into separate functions, defined in
separate files. (There are a couple reasons for this but making
dependencies clearer for makefile purposes is a big one.) Thus:
; the new pollen.rkt
(require "tags-pdf.rkt") ; defines function (pdf-bold attrs elems)
(require "tags-html.rkt") ; defines function (html-bold attrs elems)
(require "polytag.rkt") ; defines poly-branch-tag macro
(provide (all-from-out "tags-html.rkt"))
(provide (all-from-out "tags-pdf.rkt"))
(poly-branch-tag bold)
So to that end I wrote the poly-branch-tag macro, a simplified version of
which is here:
(define-for-syntax site-poly-targets '(pdf html))
(define-syntax (poly-branch-tag stx)
(syntax-parse stx
[(_ TAG:id)
(with-syntax ([POLY-FUNCS (for/list ([target (in-list
site-poly-targets)])
(list target (format-id stx
"~a-~a" target #'TAG)))])
#'(define-tag-function (TAG attributes elems)
(define poly-func (second (assq (current-poly-target)
'POLY-FUNCS)))
((eval poly-func) attributes elems)))]))
I started by using the (case) branching, but I wanted a way to be able to
add output formats in the future without fiddling with the macro every time.
All of this seemed to be working fine in my single-file DrRacket test, but
when I try this in an actual Pollen project I get an error (see end of this
post). It complains that html-bold is undefined, but it is very clearly
defined in tags-html.rkt (which also contains a (provide (all-defined-out))
directive). Indeed, I can change test.poly.pm to call html-bold directly
and that works. So calling html-bold directly works, but a macro that
evaluates to ((eval 'html-bold) args) doesn't.
I feel I must be missing some nuance of the scope in which Pollen files
work. E.g., I can run the following in DrRacket:
(define (html-bold attrs elems)
`(strong ,@elems))
((eval 'html-bold) '() '("ahoy"))
But the following in test.poly.pm gives me the same error as I get when
using my macro:
#lang pollen
◊(define (html-bold elems) `(strong ,@title))
◊((eval 'html-bold) '() '("ahoy"))
raco pollen render -t html posts/test.poly.pm
rendering posts/test.poly.pm
rendering: posts/test.poly.pm as test.html
rendering: /template.html.p as /template.html
html-bold: undefined;
cannot reference undefined identifier
context...:
...n/pollen/tag.rkt:79:10
(submod /Users/joel/Documents/code/thenotepad/posts/test.poly.pm g1083
inner): [running body]
(submod /Users/joel/Documents/code/thenotepad/post/test.poly.pm g1083):
[traversing imports]
/Users/joel/Documents/code/thenotepad/posts/test.poly.pm: [traversing
imports]
/Users/joel/Library/Racket/6.4/pkgs/pollen/pollen/private/cache-utils.rkt:33:0:
path->hash
/Users/joel/Library/Racket/6.4/pkgs/pollen/pollen/private/cache-utils.rkt:76:14:
temp16
/Applications/Racket v6.4/collects/file/cache.rkt:63:2:
fetch-and-continue
/Applications/Racket
v6.4/collects/racket/contract/private/arrow-val-first.rkt:335:3
/Users/joel/Library/Racket/6.4/pkgs/pollen/pollen/private/cache-utils.rkt:67:0:
cache-ref!
/Applications/Racket
v6.4/collects/racket/private/more-scheme.rkt:373:13: hash-ref!
/Users/joel/Library/Racket/6.4/pkgs/pollen/pollen/cache.rkt:24:4:
cached-require-base
/Users/joel/Library/Racket/6.4/pkgs/pollen/pollen/render.rkt:169:0:
render-markup-or-markdown-source33
render26
render-from-source-or-output-path
loop
(submod
/Users/joel/Library/Racket/6.4/pkgs/pollen/pollen/private/command.rkt
raco): [running body]
--
You received this message because you are subscribed to the Google Groups
"Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.