I apologize if I'm abusing the generosity of this list (and Matthew in
particular); I'm having a great deal of fun with Pollen and Racket.
I'm interested in trying to implement ordered/unordered list output in
plaintext. I'm trying to pin down whether the trouble I'm having stems from
a misunderstanding about how Pollen processes a document, or something else
related to Racket.
If the markup file looks like this, for example:
◊ol{
◊li{Direct treatment of the "thing" whether subjective or objective.}
◊li{To use absolutely no word that does not contribute to the presentation.}
◊li{As regarding rhythm: to compose in the sequence of the musical phrase,
not in sequence of a metronome.}
}
The HTML will be <ol><li>Direct treatment...</li></ol> etc. And LaTeX
similarly will be "\begin{enumerate} \item Direct treatment...
\end{enumerate}". HTML and LaTeX helpfully take care of numbering the
ordered list and so are easier cases than plaintext.
Plaintext output should be something like:
1. Direct treatment of the "thing" whether subjective or objective.
2. To use absolutely no word... (etc)
For plaintext though, we need to keep track of state (are we in a list?
what type?) and a list item counter (at least for ordered lists); and this
becomes particularly thorny with nested lists. So my first thought was a
global list; as we process the document whenever we encounter a list (an ol
or ul, or some other type of list), we push some state information onto a
sort of stack of pairs representing the type of list, and a number
representing the current note number. Something like:
(set! document-lists (cons ('unordered . 0) document-list))
And then whenever we encounter a list item, we can increment the counter in
the pair representing the current list, and use that number in the output..
(When we're done with a list, we remove it from the global document-lists
list, and in this way handle nesting).
(I've written some XSLT, and so that is shaping how I approach Pollen; I'm
uncertain though whether it's leading me astray.)
To try to get this working, I've simplified this--I'm currently not
handling nested lists, nor am I even *counting *yet. But I'm still having
trouble; as I say, I can't tell if it's b/c I'm misunderstanding scope or
binding in racket, or how Pollen processes texts.
First, I globally define some way of keeping state (here just a list *type*
):
(define list-type 'none)
Then, in the function that handles ordered lists:
(define (ol . elements)
(case (current-poly-target)
[(html) (txexpr 'ol empty elements)]
[(txt)
(set! list-type 'ordered)
(apply string-append `("\n" ,@elements)]))
And, in the function that handles list items:
(define (li . elements)
(case (current-poly-target)
...
[(txt)
(case list-type ;I think this is right; is current-poly-target is a
function; list-type just a value.
[(ordered) (apply string-append `("#. " ,@elements "\n"))])]))
If it were working, I'd also be counting the list items and inserting that
number where currently there is just a # sign. But this isn't working...
and it seems that the *set! *which changes *list-type *isn't working. After
some playing around, it seems that when list items are processed (when the *li
*function is called), the code for the *ordered *list in the case statement
isn't getting run; in *li * *list-type* still has its initial value.
So is *set! *not changing it in *ol* because I'm misunderstanding how to
use set! to keep global state. [I know, as well, that such state is
anathema to functional style---but things like numbered lists (or
footnotes) in a document seem to be a reasonable case for using mutation,
right? There is no obvious functional way of dispensing with this problem
entirely?]
*Or *am I wrong in assuming that Pollen (like XSLT) processes the document
linearly, so that I could set state information in the *ol * to affect how
its "children" (ie. the list items) are processed?
Or {entirely possible!}, have I overlooked something else?
Thanks for reading this far down!
--
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.