what are these anti webpages?

83 views
Skip to first unread message

clayton

unread,
Jan 6, 2011, 10:31:42 PM1/6/11
to antiweb
Doug,

I have a question. I've been getting exposed to web-based programming
over the past few months (php used as the backend with javascript/php
weaved within html for the pages), and although I've learned php, and
find it to be a nice high-level scripting language, it's not lisp. My
hope is that with your Antiweb server and anti webpages that I can
swap out php with lisp, and use lisp as the backend and weave lisp
within html. I'm not exactly sure if this is something that anti
webpages provide though. Are anti webpages lisp macros that transform
code down to html, a way to run a web server using lisp instead of
php, or neither/both? Ideally, if I could call out to lisp functions
straight from the html page, and weave lisp return values within the
html, that would be pretty awesome.

-Clayton

do...@hcsw.org

unread,
Jan 12, 2011, 1:19:47 PM1/12/11
to ant...@googlegroups.com
Hi Clayton,

This is a really good question. Anti webpages are an experimental way
to create web pages and applications. Some of the design decisions I
made while creating them I would now do differently.

The antiweb manual is a simple example of an anti webpage (awp). It is
included with the antiweb distribution in src/manual.awp. When used in
this way, awps are compiled completely to static HTML files. These files
(along with gzipped copies of them) are stored in the antiweb cache
directory so they can be served very efficiently with antiweb. Before
antiweb serves up these static files, it checks to see if the modification
time on the awp file has changed. If it has, it recompiles the awp before
serving the files. In this sense, awp pages are more like a content
management system than a dynamic website programming environment.

However, awps can also be used to generate dynamic content. At the lowest
level, you can include lisp code in your awp file by including it
in a progn form:

(progn
(defmacro assert-or-return-error (status msg test)
`(unless ,test
(return-from :aw-handler (build-http-response ,status (("Content-Type" "text/html")) ,msg))))
)

And you can install POST and GET handlers which are also lisp code. Here's
an (untested) example:

(post-handler "/new-entry" (args)
(www-form-bind args (id contents)
(assert-or-return-error 400 "bad id parameter"
(and (stringp id) (#~m/^\d+/$ id)))
(assert-or-return-error 400 "missing contents parameter"
(stringp contents))
(with-bdb-transaction
(setf (bdb-get "entries.db" id) contents))
(build-http-response 200 (("Content-Type" "text/plain"))
"entry added OK")))

Antiweb's bdb (BerkeleyDB) bindings are described here:

http://hoytech.com/transactional-programming.html

When antiweb receives the first request for the awp file, it extracts all
the lisp code in the awp file and stores it in a .lisp file in the antiweb
cache, then uses the lisp compiler to compile it to machine code and loads
it. When it sees that the modification time of the awp file has changed, it
recompiles the lisp code in the same was as it does for static files.

There is also functionality for regular expression parsing of your routes,
URL decoding, JSON (de)serialization, cookie extraction/setting, etc but
unfortunately it is not documented.

While awp pages do have a rudimentary templating feature, this is not
complete and I would like to seriously improve on it. The best templating
system I have seen for any language is Perl's Template Toolkit and some
day I would like to copy it for AW:

http://template-toolkit.org/

Hope this helps describe what anti webpages are a bit better.

Doug

> --
> You received this message because you are subscribed to the Google Groups "antiweb" group.
> To post to this group, send email to ant...@googlegroups.com.
> To unsubscribe from this group, send email to antiweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/antiweb?hl=en.
>

clayton

unread,
Jan 19, 2011, 6:24:02 PM1/19/11
to antiweb
Doug,

Thanks for your very helpful response. The links and examples that you
provided here will be a great place for me to start.

Will post if I have any more questions, after I've dug in a bit
deeper.

-Clayton
Reply all
Reply to author
Forward
0 new messages