Let's look at a very simple script, line by line. It's so simple it does nothing more than what our index.html does already.
- #!/usr/bin/guile -s
- (use-modules (ice-9 rdelim))
- (display "Content-type: text/html")(newline)(newline)
- (display (read-delimited "" (open-file "index.html" "r")))
Line 1-2 invoke the interpreter, /usr/bin/guile in this case. The -s flag is to let it know it's running a script.
Line 4 loads a module, a prepared package of functionality that comes with guile.
Line 6 displays some text and two newlines. The webserver expects the cgi program to take care of this. This is also an important point to understand if you're unfamiliar with cgi programming. Everything your program prints to the standard out gets sent to the browser. So if you want the visitor to see something you need to print it to standard out. In this case we use the guile (display) function to do that.
In line 8 we put that in to practice. We open a file for reading with (open-file), then we read that file with (read-delimited) which is delimited by an empty string, so it just keeps on reading until it reaches the end of the file. And finally we display everything we just read with (display).
You can see the results of the above script at
It looks exactly like
which is what we expected, since all we did was 'cat' the index.html file to the browser.