It seems that I only replied to Matthew and not the list. So, for the sake 
of completeness, I'm reposting here.

On Tuesday, September 5, 2017 at 7:00:29 PM UTC+2, Matthew Butterick wrote:
>
>
> On Sep 5, 2017, at 4:26 PM, tren...@ifi.uio.no <javascript:> wrote:
>
> Bullet-list is in my control, I was just using the example from the pollen 
> Typography for Lawyers for inspiration since it felt like writing tags for 
> every list felt too heavy, and I figured others had run into this issue 
> before. So, I can re-write it to call the correct functions.
>
>
> Leandro's advice is sound — call more functions, don't reduce to 
> X-expressions as quickly. 
>

Yes, that’s actually what I realized after reading the message. I realized 
that code was “optimized” to go straight to the final HTML (as it should). 
I need to “slow down” a little. 


> It doesn't sound like you need `eval`. I'm not an enemy of `eval`, but 
> like macros, there's often a simpler way to get the same result.
>

Indeed! eval didn’t have the right feeling. 

>
> FWIW Pollen isn't different from Racket in that regard — Racket keeps 
> evaluating expressions until it gets a value, and then stops.
>
> The weakness of my `detect-list-items` example in the `pollen-tfl` project 
> is that I only need to generate lists for HTML, so I'm reducing the result 
> immediately to an X-expression (by applying `(default-tag-function 'li)`).
>
> In your case, you'd want to take the `list-of-li-paragraphs` and pass it 
> to another function, let's call it `make-li`, that has different behavior 
> depending on whether you're targeting HTML, or LaTeX, etc.
>

Yes, that’s exactly what I did. The function is pretty similar to what you 
had. Here’s my modified functions in case anyone wonders:

(define (make-list-function tag-func [attrs empty])
 (λ args (apply tag-func attrs (detect-list-items args)))) 

(define bullet-list (make-list-function ul))

(define (detect-list-items elems)
 (define elems-merged (merge-newlines elems))
 (define (list-item-break? elem)
   (define list-item-separator-pattern (regexp "\n\n\n+"))
   (and (string? elem) (regexp-match list-item-separator-pattern elem)))
 (define list-of-li-elems (filter-split elems-merged list-item-break?))
 (map (λ(lip) (apply li lip)) list-of-li-elems))



My make-list-function takes a function instead of a symbol (here my ul 
function) and I call my li function instead of decode-paragraphs. It works 
exactly as I expected for HTML and LaTeX. Though it feels worthwhile making 
aliases for these functions to unordered-list and list-item now that I 
don’t call them directly.

Thanks for the extra help, Leandro and Matthew. Sometimes explaining things 
to others help unclog your thought process.

Best regards,

— 
Trenton
 

-- 
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 pollenpub+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to