[plt-scheme] programming for the web in scheme
vlado wrote:
> I suppose I should start with "I'm an absolute beginner with scheme", so
> be harsh with me, please :)
>
> I started playing with plt scheme because I grew very frustrated with
> going to incredible lengths to twist the arms of other languages to be
> able to program lazily, that is I want the computer to do the thinking
> more than me. Having said that, I quite like a lot of the ideas I've
> learnt or developed over the years and I would love to continue to use
> them.
>
> Things what attract me to scheme - the mini languages approach to
> programming is probably the most important, first class functions and
> call/cc and friends close second.
>
> I've been playing a little with the web-server but have the problem that
> I need to often guesstimate or dive into code reading to find what is
> going on behind the scenes. It would be fine if I was more fluent with
> the language, but I'm not.
Some small tips.
1. *Always* click at at "Check Syntax" before running your servlet
in the web-server.
2. Use
(report-errors-to-browser send/finish)
while developing to get error messages.
3. Remember to restart the web-server on each change
(is there a way to make a servlet non-cached?)
4. Use the module language to test the start function from within
DrScheme. E.g (start 'foo) if your servlet never uses the request, or
use
(start
(make-request symbol url environment environment string string)
where the arguments are: method, uri, headers, bindings, host-ip, and
client-ip)
Save this in default-web-root/servlets/examples/date.ss
(module date mzscheme
(require (lib "servlet.ss" "web-server"))
(provide interface-version timeout start)
(define interface-version 'v1)
(define timeout +inf.0)
; start : request -> response
(define (start initial-request)
(report-errors-to-browser send/finish)
`(html (head (title "Date Example"))
(body (h1 "Date Example")
(p "The date and time is"
,(date-and-time (/ 1 0))))))
(require (lib "date.ss"))
(define (date-and-time)
(date->string (seconds->date (current-seconds)))))
and see the error message at
<http://localhost/servlets/examples/date.ss>
then remove the (/ 1 0) to see a functioning servlet.
--
Jens Axel Søgaard