[plt-scheme] literal html data in servlets

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Aug 19 14:57:57 EDT 2005

On Aug 19, Hans Oesterholt-Dijkema wrote:
> Eli Barzilay schreef:
> 
> >On Aug 19, Hans Oesterholt-Dijkema wrote:
> >
> >>It's a hack, but it works! Thanks! Wrapped it as follows:
> >>
> >>(define-syntax make-literal
> >>  (syntax-rules ()
> >>    ((_ s1 ...)
> >>     (make-comment (format "-->\n~a\n<!--" (string-append s1 ...))))))
> >
> >Why not a plain function?
> 
> Less overhead?

That's a dangerous argument -- you should make sure that the overhead
from using a function is substantial enough to justify a macro.
Macros are less convenient to deal with, if only due to the fact that
you can no longer treat it as a first class object to pass it around
or to apply it on a list of things.

In Swindle I have a `defsubst' syntax that is intended to define
simple macros, you'd write the above as:

  (defsubst (make-literal s1 ...)
    (make-comment (format "-->\n~a\n<!--" (string-append s1 ...))))

or

  (defsubst (make-literal . strings)
    (make-comment (format "-->\n~a\n<!--" (string-append . strings))))

In the second form you can simply replace `defsubst' with a `define'
and it will work the same.  This thing makes it very easy to replace
functions with macros, and from this I learned that it is not always
worth it to do that -- it's tricky to know when you actually buy
performance and how much of it, and sometimes you get into weird
situations that happen because it's a macro and not a function.
-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!



Posted on the users mailing list.