Data. I define blog as a set of properties: id , created-at and content . We can define this blog as follows:

;; path: b/entities/blog.lisp

(defpackage :b.entities.blog

(:use :cl)

(:export :make-blog

:blog-id

:blog-created-at

:blog-content))

(in-package :b.entities.blog) (defstruct blog id created-at content)

Here, you can see that the root package name of the application is b . …Yes, I know it’s not cool, but I have no any better idea right now. Anyway, I go on writing the code.

I put the definition above in the b/entities/blog/blog.lisp file. I often put the data definitions, in which the rules of an application is written, in the entity layer. These definitions are the most important building blocks for the application.

The id of a blog is used for identifying the blog from others. Therefore each id must be unique over the application lifetime.

There are several ways to generate such unique ids: UUID or generating them by an auto increment column (for MySQL users). You can select any of them if it can accomplish this task. Here is an example implementation in Common Lisp:

(defpackage :b.entities.id

(:use :cl)

(:export :gen

:uuid-generator))

(in-package :b.entities.id) (defgeneric gen (generator)) (defclass uuid-generator () ())

(defmethod gen ((generator uuid-generator))

...)

Persistence. Persistence is indispensable to a web application. Even when what is persisted is not clear.

In English, we might often say “Save the blog to the database (db)”. This can be translated into Common Lisp directly as follows:

(save db blog)

This expression contains sufficient information of the sentence “Save the blog to the db”, and no more tokens can be removed from the expression without losing the meaning of the sentence.

A typical implementation of db would be MySQL, and that of the save function would be sending queries to the database, which are shown below:

(defun save (db blog)

(execute (prepare db "INSERT INTO blog ..."))

db)

I like to return db as the return value of the function.

Although this implementation works well, using an O/R mapper such as mito helps us reducing the amount of the common code for persistence.

“Save the blog to the db” is a part of the processes of an application. I often want to write the code as closely as the original English sentence of an application. I often define abstract functions by which I can describe application processes as naturally as I do in English.

However, abstract functions might not perform well. If that happens, I have to consider using raw level functions of the specific db implementation. I might give up providing the high level save function above, and end up with providing raw level functions such as insert-<something> .

If you have to switch several implementations of save , defining it as a method using defgeneric would be a good choice.

(defgeneric save (db blog)) (defmethod save ((db mysql-db) (blog blog))

...

db) (defmethod save ((db file-db) (blog blog))

(with-open-file (stream (format nil "~A/~A.lisp"

(file-db-path db)

(blog-id blog))

:direction :output)

...)

db)