Feeds:
Posts
Comments

Archive for June, 2007

Seaside has inspired me to try to write a basic HTML/CGI based grid style widget. In Seaside, that widget is called WATableReport which is described here and provides column sorting as is available in most decent GUI widget sets. My web-fu is a little rusty. Last time I was writing web code was back in the dark ages pre-servlets and nice session managing frameworks using pure CGI. This may well be available somewhere already but what the heck, let’s get started…

First of all, we need a data-type for the table data. For now we will keep it simple and just have the column names and the data which will probably be a list of lists.

(define-struct table-data (columns data))

We will need to serialise the data so we can pass it to another page through the query string. I briefly toyed with the idea of having some custom format of lists of comma seperated values surrounded by square brackets. e.g.

[Task, Monday, Tuesday, Wednesday],
[Cooking, 1hr, 1hr, 2hrs],
...

The parser tools supplied with PLT Scheme would make this fairly straight-forward. Even easier is using the read and print functions so we will go with that. I also want to be able to define a whole package of data for testing purposes and escaping every quote will be a pain so let me allow single quotes too. I had a look in the Scheme Cookbook for a simple way to transform characters within a string. string-map from srfi-13 offered a possibility, but we will almost certainly want something more powerful later so we might as well start with regexes.

(require (lib "pregexp.ss"))

(define (string-encode s)
  (pregexp-replace* "'" s "\""))

Together with a function to convert strings to scheme objects we can provide a convenience function for converting manifest strings into our data.

(define (string->object s)
  (read (open-input-string s)))

(define (string->data s)
  (string->object (string-encode s)))

(define *data* #f)

(set! *data*
      (string->data
       "(('Task' 'Monday' 'Tuesday' 'Wednesday')
         ('Cooking' '1hr' '1hr' '2hrs'))"))

Next time we will look at encoding the data so we can pass it through the query string. At the moment, we will have a small problem with quotes and a few other characters…

(define (print-ln . args)
  (for-each print args)
  (newline))

(print-ln "<a href=\"ser.scm?data=" *data* "\">next page</a>")

> "<a href=\"ser.scm?data="(("Task" "Monday" "Tuesday" "Wednesday") ("Cooking" "1hr" "1hr" "2hrs"))"\">next page</a>"

Read Full Post »

After fiddling around for a couple of minutes I found the correct incantation to get cgi scripts to work with Windows Apache. It uses the traditional Unix hash-bang line. Here we have a nice little hello world cgi:

#!mzscheme -mqf

(define *query-string* (getenv "QUERY_STRING"))

(define (header type)
  (string-append "Content-type: " type "; charset=iso-8859-1~n~n"))

(printf (header "text/html"))
(printf "Hello World~n")

(when *query-string*
      (printf "[~a]~n" *query-string*))

(exit)

But why bother with CGI when there are all these wonderful frameworks around? Isn’t that old-school? Well, I’ve been inspired by something in Seaside. I’m not thinking of porting the whole framework, no way. If I wanted to, then why not just use Seaside? No, I want to try something much smaller.

Read Full Post »

Virtual Machines

Targeting a ubiquitous virtual machine is all the rage these days. All the cool kids are doing it. On the client-side, everything is the browser and/or flash with silverlight “coming soon”. On the server things are not much different with every man and his language running on the JVM or .NET. Of course HaXe follows this very sensible tradition and runs on both flash and the browser (and more) on the client and, erm, Neko on the server.

Neko?

So, why does HaXe target Neko? Well, it is common knowledge that on the server, it doesn’t really matter what you run. As long as you are web enabled, no-one cares. Actually, that is only true for the small number of people who run their own server. A far larger group of people write code that runs on a free host.

PHP

PHP isn’t usually thought of as a virtual machine but it is very common on free hosts. If you are writing your own compiler, you can target whichever runtime you like including PHP. I know Neko has many advantages over PHP including a huge speed advantage but ubiquity counts for lot. I suspect a PHP backend for HaXe would boost the number of potential users through the roof.

Read Full Post »

Follow

Get every new post delivered to your Inbox.