Daniel Sockwell
未读,2019年4月12日 10:51:092019/4/12登录即可回复作者
登录即可转发
您无权在此群组中删除帖子
请登录以举报消息
要么此群组的电子邮件地址为匿名状态,要么您得查看成员电子邮件地址权限才能查看原始帖子
收件人 poll...@googlegroups.com
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!)