[racket-dev] Racket on Rockets

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Jul 26 13:20:59 EDT 2011

I was recently telling some people that I thought 'Ruby on Rails' was
mostly an ORM plus a set of default dispatching rules with convenient
ways of extending the defaults.

I don't have a lot of expertise on the ORM side, but I think Snooze
would probably be awesome and my MongoDB-backed structs may be helpful

On the side of default dispatching rules, I've made a little demo:


[For the demo, the ORM is just hash tables of structs.]

This program:

#lang racket/base
(require "ror.rkt")

 [posts (title body)])

is an incredibly generic "blog" where you can see all the posts, add
new ones, and edit old ones. It sets up a slew of un-hygienic names
and allows you to override them to replace default behavior.

This program uses that overriding feature to replace the top-level index:

#lang racket/base
(require web-server/servlet

(define (post-render id)
  (define obj (hash-ref *posts* id))
  `(div (h2 ,(posts-title obj))
        ,(posts-body obj)))

(define (index req)
     (head (title "My Racket on Rockets blog"))
      (h1 "My Racket on Rockets blog")
      ,@(for/list ([last-post-n (in-range 5)])
          (define post-id (- (hash-count *posts*) (add1 last-post-n)))
          (if (negative? post-id)
              (post-render post-id)))
      (p (a ([href ,(to-url posts-new)]) "New Post") " "
         (a ([href ,(to-url posts-index)]) "All Posts"))))))

 [posts (title body)])

You could also define posts-new or posts-index to control the
corresponding default functions.

In case what I had in mind wasn't clear... I hope this is.


Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

"The glory of God is Intelligence" - D&C 93

Posted on the dev mailing list.