chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] web-scheme & hart


From: Graham Fawcett
Subject: Re: [Chicken-users] web-scheme & hart
Date: Thu, 6 Mar 2008 09:37:42 -0500

On 05 Mar 2008 23:29:19 -0300, Mario Domenech Goulart
<address@hidden> wrote:
>  On Wed, 5 Mar 2008 17:45:42 -0800 Robin Lee Powell <address@hidden> wrote:
>
>  > It seems to me that web-scheme and hart do more-or-less the same
>  > thing.
>  > 2.  What's the difference between web-scheme and hart?  Do people
>  > have preferences between the two?
>
>  I don't know much about hart.  I think Graham can write about it.

Briefly, Hart is a syntax extension that tries to turn as much of your
"html expression" into simple print statements at macro-expansion
time. The base-case, where nothing in your expression requires
variable-substitution, turns into a single print statement:

#;2> ,x (hart (h1 (@ (id "main")) "hello"))
(noop (begin (hart-print "<h1 id=\"main\">hello</h1>")))

Adding variables makes it a bit more verbose at expansion time.

#;2> ,x (hart (h1 (@ (id my-h1-id)) (t: my-h1-text)))
(noop (begin
        (hart-print "<h1")
        (let ((g3 my-h1-id))
          (when g3 (hart-print " id=\"" (hart-html-escape g3) "\"")))
        (hart-print ">")
        (apply hart-print (map hart-html-escape (list my-h1-text)))
        (hart-print "</h1>")))

My goal was to develop a nice syntax, but also to reduce runtime
overhead as much as possible. I've never properly benchmarked it
against other options (I haven't used Mario's egg; I used to use the
shtml->html option in the htmlprag egg). Also, I haven't really tried
to optimize it, beyond compiling with an -On flag, and using a
fast-if-primitive html-escape routine. I guess I found that it was
efficient enough for my needs.

One thing I'd like to add is better support for HTML entities,
probably following SXML syntax:

(hart (p "Come back to the five " (& "amp") " dime, Jimmy Dean..."))

right now you need to use a (raw: ...) or (scheme: ...) block to do that:

(hart (p (raw: "Come back to the five &amp; dime, Jimmy Dean...")))
(hart (p "Come back to the five " (raw: "&amp;") " dime, Jimmy Dean..."))
(hart (p "Come back to the five " (scheme: (print "&amp;")) " dime,
Jimmy Dean..."))

Hope this helps. Comments and suggestions are always welcome.

Graham




reply via email to

[Prev in Thread] Current Thread [Next in Thread]