I just noticed an error in my earlier example: I listed two films as `(book)`. To be clear, all of the children of `(films)` should have been films, not books. That error was unintentional, but underscores my point a bit: because the semantics were stripped out of the X-expression, it was much harder to catch that error!
On Friday, April 12, 2019 at 10:51:09 AM UTC-4, Daniel Sockwell wrote: > > After reading through the Pollen documentation, I'm extremely sold on the > power of semantic markup. But I'm a bit confused about whether to preserve > semantics in the generated X-expressions and, if so, how we would do so. > > Consider the following toy example: > > ``` > #lang pollen > > ◊(books (book "The Hitchhiker's Guide to the Galaxy") > (book "Catch 22") > (book "The Name of the Wind")) > ◊(films (film "Star Wars: A New Hope") > (book "One Flew Over The Cuckoo's Nest") > (book "The Hitchhiker's Guide to the Galaxy")) > ``` > > This is nicely semantic markup and, by default, produces an equally > semantic X-expression: > > ``` > '(root > (books > (book "The Hichhiker's Guide to the Galaxy") > (book "Catch 22") > (book "The Name of the Wind")) > "\n" > (films > (film "Star Wars: A New Hope") > (book "One Flew Over The Cuckoo's Nest") > (book "The Hick hiker's Guide to the Galaxy")) > "\n") > ``` > > However, this markup does not (yet) produce valid HTML. If we want it to > produce valid HTML we could define functions like this in our `pollen.rkt` > file (these are toy examples that leave a lot out for simplicity): > > ``` > #lang racket > (require pollen/tag > pollen/decode) > (provide (all-defined-out)) > > (define (books . elements) `(ul ,@elements)) > (define (book title) `(li ,title)) > > (define (films . elements) `(ul ,@elements)) > (define (film title) `(li ,title)) > ``` > > Now our nice semantic markup produces valid HTML, exactly as we wanted. > > However, we've now lost the semantics in our generated X-expression. > We're now getting > > ``` > '(root > (ul > (li "The Hitchhiker's Guide to the Galaxy") > (li "Catch 22") > (li "The Name of the Wind")) > "\n" > (ul > (li "Star Wars: A New Hope") > (li "One Flew Over The Cuckoo's Nest") > (li "The Hitchhiker's Guide to the Galaxy")) > "\n") > ``` > > In addition to not looking as pretty, the loss of our semantic tags in the > X-expression means we can't do things like write a decoder that > distinguishes between `(book "The Hitchhiker's Guide to the Galaxy")` and > `(film "The Hitchhiker's Guide to the Galaxy")`. In general, my intuition > is that the semantics should be preserved as long as possible and only > stripped out when taking the final step of transforming out data to the > output format (here, HTML). But I'm not sure if that's possible/worth the > effort. > > This leads me to the question I started with: is there a better approach > that would preserve the semantic meaning in our generated X-expression > (while still yielding valid HTML)? Or does it just not make sense to try > to preserve semantics in the X-expression, given that we have semantics in > the markup? I played around with `(decode)` a bit and couldn't get it to > work for this. But I wasn't sure if that's because I don't yet fully > understand `(decode)` or because I was trying to get it to do something it > wasn't meant to do. > > I'd appropriate anyone's perspective on this. > > (By the way, Matthew, thanks very much for your helpful replies to my > recent questions. I haven't replied just to say "thanks" out of a desire > not to spam the group, but I very much appreciate your help!) > > > > > > -- 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.
