-
Notifications
You must be signed in to change notification settings - Fork 0
beginner questions #18
Comments
History has taught me that it’s difficult to answer these questions in the abstract. It would be better for you to post a concrete example of something that doesn’t work the way you expect. Mostly, Pollen is a more convenient way of writing Racket programs that process a lot of text, using X-expressions as the medium of exchange. Some people like it better than Scribble; some people don’t 😉 |
Here’s a working example for your second question. Every Pollen document So we can write an
#lang racket/base
(require pollen/core pollen/decode)
(provide root include)
(define (root . elems)
`(body ,@(decode-paragraphs elems #:force? #t)))
(define (include file)
`(@ ,@(cdr (get-doc file))))
#lang pollen
◊h1{My Included File}
It feels ◊strong{good} to be included.
#lang pollen
◊h1{Main File}
I'm not complete on my own...
◊include["other-file.html.pm"] Saving all of these in the same folder and "running"
|
Thanks for the working example. It works. And seems a lot simpler than anything similar I've found in Scribble. And it puts the included text exactly where I include it. The closest thing in Scribble creates a formal subsection and moves it to the end, which is one thing I do not need or want. It does seem to demand that I place a #lang pollen at the start of the included file. I had to make one change: if the stuff from the included file ends up being just one string, and not a list, the cdr fails; instead I have to wrap to make the cdr succeed. I'm guessing that in this case it leaves out the call to root? Is this a bug or a feature? Hmmm. Why would it do that? I'll have to try an included file with some losenges in it do see if it's any different. |
Lots of missing information here. As Matthew said earlier, the best way for us to help is if you can provide a concrete example of something that does not work they way you expect. Another thing I always recommend to people: work through the [four tutorials][1] in the Pollen docs — actually type out and run the examples in DrRacket. Even if you think you can understand the concepts just by reading. |
Regarding your 4th question in your original post, you may be interested to read this discussion on the old Google groups list. The approach would be to use the |
So pollen uses the Racket module mechanism to include files, and so they have to be Racket modules. Does that mean that it's possible to include a Scribble module into a Pollen file? I suspect not; I suspect there will be incompatibilities. |
Regarding the fourth question. The markdown package you refer me to describes a function parse-markdown. But it takes a path or a string as argument, but doesn't a lozenge-function instead receive a list of x-expressions? |
Per the docs:
So if a Scribble module can be made to do |
There is no such thing as a lozenge-function. The lozenge is just how you signal to Pollen that what follows should be interpreted as Racket code instead of as literal text. Further, a string is a valid x-expression. |
Regarding the fourth question. The markdown package you refer me to describes a function parse-markdown. But it takes a path or a string as argument, but doesn't a lozenge-function instead receive a list of x-expressions? |
#lang pollen/markup
◊(require markdown racket/string)
◊(define (md . strs)
(cons '@ (parse-markdown (string-join strs ""))))
Before the markdown block.
◊md{**hello**
there!
_world_}
After the markdown block. Result:
|
About the include function you provided. It seems to require that the returned Here's the case I'm having trouble with. The included file,
I get the error message
etc. etc. The problem seems to be that the value of doc that's returned is just a string, and not For completeness, the including file:
and the pollen.rkt file:
|
Try renaming wiko.mt3 to wiki.html.p?
…On Fri, Nov 8, 2019, 8:43 AM hendrikboom3 ***@***.***> wrote:
About the include function you provided. It seems to require that the
returned doc value be a pair.
But sometimes it isn't. Is this a bug or a feature? And if a bug, is it a
bug in pollen or a bug in include?
Here's the case I'm having trouble with. The included file, wiko.mt3, is
truly trivial:
#lang pollen
xx yyy
I get the error message
***@***.***:~/write/Melinda.pollen/Melinda/src$ raco pollen render wko.html
pollen: rendering wko.html
pollen: rendering /wko.poly.pm as html
cdr: contract violation
expected: pair?
given: "xx yyy"
context...:
/home/hendrik/write/Melinda.pollen/Melinda/src/pollen.rkt:10:0: include
(submod "/home/hendrik/write/Melinda.pollen/Melinda/src/wko.poly.pm" pollen-module): [running body]
temp37_0
for-loop
run-module-instance!125
etc. etc.
The problem seems to be that the value of doc that's returned is just a
string, and not root consed onto the beginning of anything. Evidently the
running example you provide is too complex to trigger this problem.
For completeness, the including file:
#lang pollen
◊include["wiko.mt3"]
and the pollen.rkt file:
#lang racket/base
(require pollen/core pollen/decode)
(provide root include)
(define (root . elems)
`(body ,@(decode-paragraphs elems #:force? #t)))
(define (include file)
`(@ ,@(cdr (get-doc file))))
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#18?email_source=notifications&email_token=ACFNSOMF6NJ6IG64MB5GTVTQSWJKHA5CNFSM4JIX2SC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDSVR7Y#issuecomment-551901439>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACFNSOIROG3TIGDHFNYRV5DQSWJKHANCNFSM4JIX2SCQ>
.
|
I meant wiko.html.pm. Sorry for the error. I was typing this on my phone.
On Fri, Nov 8, 2019, 9:42 AM Sorawee Porncharoenwase <
sorawee.pwase@gmail.com> wrote:
… Try renaming wiko.mt3 to wiki.html.p?
On Fri, Nov 8, 2019, 8:43 AM hendrikboom3 ***@***.***>
wrote:
> About the include function you provided. It seems to require that the
> returned doc value be a pair.
> But sometimes it isn't. Is this a bug or a feature? And if a bug, is it a
> bug in pollen or a bug in include?
>
> Here's the case I'm having trouble with. The included file, wiko.mt3, is
> truly trivial:
>
> #lang pollen
>
> xx yyy
>
>
> I get the error message
>
> ***@***.***:~/write/Melinda.pollen/Melinda/src$ raco pollen render wko.html
>
> pollen: rendering wko.html
>
> pollen: rendering /wko.poly.pm as html
>
> cdr: contract violation
>
> expected: pair?
>
> given: "xx yyy"
>
> context...:
>
> /home/hendrik/write/Melinda.pollen/Melinda/src/pollen.rkt:10:0: include
>
> (submod "/home/hendrik/write/Melinda.pollen/Melinda/src/wko.poly.pm" pollen-module): [running body]
>
> temp37_0
>
> for-loop
>
> run-module-instance!125
>
>
> etc. etc.
>
> The problem seems to be that the value of doc that's returned is just a
> string, and not root consed onto the beginning of anything. Evidently
> the running example you provide is too complex to trigger this problem.
>
> For completeness, the including file:
>
> #lang pollen
>
>
>
> ◊include["wiko.mt3"]
>
>
> and the pollen.rkt file:
>
> #lang racket/base
>
>
>
> (require pollen/core pollen/decode)
>
>
>
> (provide root include)
>
>
>
> (define (root . elems)
>
> `(body ,@(decode-paragraphs elems #:force? #t)))
>
>
>
> (define (include file)
>
> `(@ ,@(cdr (get-doc file))))
>
>
>
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#18?email_source=notifications&email_token=ACFNSOMF6NJ6IG64MB5GTVTQSWJKHA5CNFSM4JIX2SC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDSVR7Y#issuecomment-551901439>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACFNSOIROG3TIGDHFNYRV5DQSWJKHANCNFSM4JIX2SCQ>
> .
>
|
Yes. renaming the file worked. The naming of files has become a black art. |
Again, read the docs thoroughly, they are really helpful. There isn’t really defined behavior for what happens when you use random file extensions. If you aren't going to use the default file extensions, you should change the appropriate parameters to reflect your choices. |
To supplement @otherjoel’s answer: your question about file naming is also addressed in the first tutorial and emphasized with the warning Don’t skip this section! It explains an essential Pollen concept. (It is not the only section so labeled.) I can guarantee that if you insist on learning Pollen by avoiding these essential concepts, then yes, everything will seem like “black art”, I’m afraid. |
Yes. renaming the file worked. The naming of files has become a black art. |
I had read the section about file names, but I did not realize that it applied to the files I included, since the source file were fully identified in the ◊include request and all decisions as to source format and object format has already been made based on the name of the main source and object file. It's not as if I was asking it to make linked output files, each in a different output format. As for the extensions I was using, they were already there in the files I was trying to convert to pollen. |
(1) It looks as if document structure and design is pretty much a do-it-yourself thing with pollen. But I suspect there are a number of pre-built lozenge commands that are available, whether as part of the pollen distribution or some kind of community folklore. Is there a list of these?
(2) One feature I need is file inclusion. Ideally something like ◊include["filename"] to include another file as if its contents were present in the place of the lozenge command. I've tinkered with scribble and not succeeded. In particular I've been unable to get all its at-commands (succh as @(require ...) working reliably from included text. More seems to be involved there than merely calling elem to to necessary conversions after the at-reader has done its work.
I hope it's simpler in pollen.
(I would not mind a restriction that the syntax be properly nested. I have no need to match an open bracket in one file with a close bracket in another, and would appreciate an error message if I seem to be trying that!)
(3) Not as essential, but would be nice: using the markdown parser on part of a document. Something like:
ordinary pollen stuff
◊markdown{ a page or two of markdown-style bullet-point notation }
more ordinary pollen stuff.
(4) Is there a way to indicate that the output file should be somewhere other than in its default location; e.g., in another directory?
-- hendrik
The text was updated successfully, but these errors were encountered: