1 Installing LeftParen
2 Tutorials
2.1 Hello, World
2.2 Blogerton the Blog
2.2.1 Changes to app.scm
2.2.2 Changes to main.scm
2.2.3 Launch Blogerton
3 About/ Acknowledgements
Version: 3.99.0.17

LeftParen Documentation

Website: http://leftparen.com

LeftParen is a framework for quickly creating web apps. It runs on PLT Scheme v399 or greater.

1 Installing LeftParen

You’ll need PLT Scheme v399 or greater installed. Note that this version is not officially released yet, so you you’ll need to get it from the pre-release download page.

Make sure that mzscheme is in your path. You should be ready to go if you can do this:

% mzscheme

Welcome to MzScheme v3.99...

>

Note that the particular version of MzScheme you have is likely unimportant, as long as it’s 3.99 or higher.

Installing LeftParen proper is done with a PLaneT require. See Tutorials for an example of this. When you first issue one of these require commands, you’ll automatically download the LeftParen files to your local PLaneT cache. This can sometimes take a few moments, so be prepared to wait a bit.

2 Tutorials

2.1 Hello, World

We’re going to make a project called hello-world. Change to the directory that you’d like to make the project in. Then issue

% mzscheme -e '(require (planet "bootstrap.scm" ("vegashacker" "leftparen.plt" 1 0)))' project hello-world

This will create a hello-world project directory for you. In this directory you’ll find the script directory, which contains some useful scripts. We need to make these scripts executable though:

% chmod u+x hello-world/script/*

LeftParen has automatically generated everything we need to run our web app – we just need to start the server:

% ./hello-world/script/server

Web server started on port 8765

Listening on IP address: 127.0.0.1

Type stop to stop the server and exit

Type restart to restart the server

Point your browser to http://localhost:8765 and you should see a familiar greeting:

Hello, World!

2.2 Blogerton the Blog

Now let’s try implementing the true "hello world" of web apps – a blog. First, execute the following commands from the directory in which you want to create your project directory:

% mzscheme -e '(require (planet "bootstrap.scm" ("vegashacker" "leftparen.plt" 1 0)))' project blogerton

% chmod u+x blogerton/script/* }

2.2.1 Changes to app.scm

We need to register a couple of pages in our app. The index-page was already set up for you, but you’ll need to add a page to create new posts, and one to view them. Make the define-app call look like this:

  (define-app my-app

    (index-page (url "/"))

    (create-post-page (url "/post"))

    (view-post-page (url "/view/" (string-arg))))

2.2.2 Changes to main.scm

Now we need to define those pages that we declared in app.scm.

  (define-page (index-page req)

    `(h1 "Blogerton")

    `(p ,(web-link "Create a new post" (page-url create-post-page)))

    `(ul ,@(map (lambda (p) `(li ,(paint-blog-post p)))

                (load-where '((type . blog-post))

                            #:sort-by 'created_at #:compare >))))

  

  (define-page (create-post-page req)

    (form '((title "Title" text) (body "Body" long-text))

          #:init '((type . blog-post))

          #:on-done (lambda (post) (redirect-to-page view-post-page (rec-id post)))))

  

  (define-page (view-post-page req post-id)

    (paint-blog-post (load-rec post-id #:ensure '((type . blog-post)))))

  

  (define (paint-blog-post post)

    `(div (h2 ,(rec-prop post 'title))

          (p ,(rec-prop post 'body))))

2.2.3 Launch Blogerton

You’re ready for launch. Start the server with

% ./blogerton/script/server

and you should have a basic blogging app, with persistent data, in 19 lines of code.

3 About/Acknowledgements

LeftParen was written by Rob Hunter, but it builds heavily on (and, in fact, often directly incorporates) the work of Untyped (instaservlet and dispatch), Jens Axel Soegaard (web.plt), and of course, PLT Scheme.