6 ms·
Not sure I buy it. My favorite language is Scheme (specifically, PLT Scheme). You'll find no macros below: (define (whitepage . content) `(html (body ,
by vegashacker 17y ago
Not sure I buy it. My favorite language is Scheme (specifically, PLT Scheme). You'll find no macros below:
(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.
- gms 17y agoJudging by the HTML macros he talks about in ANSI Common Lisp, they had to be macros since they output HTML to file using a bunch of FORMAT calls. Since side-effects were involved and the calls had to be evaluated at specific points before and after other such calls, they had to be macros.
- vegashacker 17y agoAh ha! Thanks, gms. But this brings us to the question... are we getting anything by using side-effecty print statements to make web pages? I don't see it. I think I vastly prefer building up my markup functionally, and then handing it off to the web server when done. Plus, with the PLT way, you avoid writing macros. And a wise man once wrote, "It's considered to be bad style to use [macros] when they're not necessary." ;) 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.
- gms 17y agoYes I prefer your approach too (I use a similar approach with the Elisp I use to publish posts on my blog). You are also right that one shouldn't use a macro where a function would do. 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).
- pmarin 17y agoBut your result is not html. In the Arc library the arguments of the tags, like whitepage are any expression and only tag the stdout (you can redirect the output to another port). For example: (= a 1) (whitepage (= b (+ a 1)) (pr b)) And you obtain: <html><body bgcolor=#ffffff alink=#0000be>2</body></html>