(define (whitepage . content)
`(html (body ,@content)))
(define (para)
`(p))
(define (link prose url)
`(a ((href ,url)) ,prose))
(define (prbold text)
`(strong ,text))
So the example from the Arc link (whitepage "Hello world!" (para) (link "Click here" "http://news.ycombinator.com")
"for" (prbold "more stuff"))
yields (html
(body
"Hello world!"
(p)
(a ((href "http://news.ycombinator.com")) "Click here")
"for"
(strong "more stuff")))
which is a valid expression that PLT's web server will render as a web page.Okay...I'll leave my "Are we getting anything" question there, but it probably shouldn't be answered. Or at least not here. It's essentially the pure-functional versus side-effect debate. To be fair, you get benefits from both, and both have downsides that the others are better at.
When looking at PG's approach in ACL, it's worth remembering that he came up with it more than 10 years ago, and consider it in that context. The surrounding ecosystem for web development was a lot more primitive back then (which serves to highlight how impressive his idea is/was).
(= a 1)
(whitepage (= b (+ a 1)) (pr b))
And you obtain: <html><body bgcolor=#ffffff alink=#0000be>2</body></html> (mac uvar (u k) `((profs* ,u) ',k))
(def user-age (u) (hours-since (uvar u created)))
Without a macro you'd have to call uvar like: (uvar u 'k). For this example I'd favor 'k because it makes the behavior clearer.(Did you mean uvar instead of upvar?)
If you are using macros you may start sending the html parts before the whole page is constructed.
The latter approach is advantageous if a page needs some heavy computations to generate it: with macros the user will start seeing at least something right away; plus, the browser will load CSS faster if you send that part before the computations.
On the other hand if there was an error in the middle of page generation you will not be able to handle it gracefully since you've already send half of the page to the user.
Not necessarily... even using functions, you can create a 'lazy node' in the page graph to delay completion of calculation until the final renderer actually starts rendering the node.
I guess the only advantage of using macros is that you can make page generation code without consing relatively easily. I'm not sure how necessary it is for web servers, but it may matter for extremely high-traffic sites.