The VikiD Truth

Knowledge base / Computing / Lisp family

The Health Application

Health is a small application that I co-wrote with Alexander Burger to help newcomers understand the nuts and bolts of a very simple PicoLisp application.

It uses the standard libraries, especially http.l, @lib/xhtml.l and @lib/form.l. The app consists of two files, health.l and day.l, whose sources are given below.

Sources

health.l

# 09may17abu
# (c) Software Lab. Alexander Burger

(allowed ()
   "!work" "@lib.css" "day.l" )

(load "@lib/http.l" "@lib/xhtml.l" "@lib/form.l" "@lib/adm.l")

(class +Day +Entity)
(rel dat (+Key +Date))                 # Date
(rel w (+Number) 3)                    # Weight [kg]

(dm T @
   (pass super 'dat (date)) )

(dm url> ()
   (list "day.l" '*ID This) )

(de choDay (Dst)
   (choDlg Dst "Days" '(dat +Day)
      NIL
      '(pack (datStr (: dat)) ": " (format (: w) 1)) ) )

(de menu (Ttl . Prg)
   (action
      (html 0 Ttl "@lib.css" NIL
         (<ping> 7)
         (<layout>
            ((180 0 'menu)
               (<div> @
                  (expires)
                  (<menu>
                     (,"Home" "!work")
                     ("Day" "day.l") ) )
               ((NIL NIL 'main)
                  (<div> @ (run Prg 1)) ) ) ) ) ) )

(de work ()
   (app)
   (menu "Health"
      (<h2> NIL "Health") ) )

(de main ()
   (pool "health.db") )

(de go ()
   (server 8080 "!work") )

# vi:et:ts=3:sw=3

day.l

# 09may17abu
# (c) Software Lab. Alexander Burger

(menu "Day"
   (idForm "Day" '(choDay) 'dat '+Day T '(may Delete) '((datStr (: dat)))
      (<grid> 2
         "Date" (gui '(+E/R +DateField) '(dat : home obj) 10)
         "Weight" (gui '(+E/R +FixField) '(w : home obj) 3 7) )
      (<spread> NIL (editButton T)) ) )

# vi:et:ts=3:sw=3

Walking through Health

The sources above are the whole application. It is worth reading slowly, because almost every line shows off one idea from PicoLisp’s application framework. The code was written in 2017, and I re-ran it unchanged on PicoLisp 26.9 (pil21) in October 2026: current PicoLisp kept the same @lib/http.l, xhtml.l, form.l and adm.l libraries.

The plain idea

Health is a tiny weight diary. Each record is a Day: a date and a weight in kilograms. You can create days, edit them, search for them, and delete them, all through a web browser, with the data stored in a PicoLisp database file, health.db. There is no separate database server, no template language and no JavaScript framework. The data model, the user interface and the web server are all written in the same Lisp, in about fifty lines.

Why it matters

Most web frameworks spread one small app across a dozen files and three or four languages. Health shows the opposite extreme: a complete database-backed web app you can hold in your head. That makes it an ideal first study for anyone who wants to understand how PicoLisp applications are put together, before tackling the much bigger demo app (demoApp.tgz, explained in the application tutorial).

An everyday analogy: a notebook with a librarian

Think of the database as a notebook where each page is a Day. The +Day class is the printed form at the top of each page (date, weight). choDay is the librarian you ask “show me all the days”, and day.l is the page you open to read or correct one entry. The server is simply the shop counter where the librarian waits for you.

A worked example: reading health.l

pil health.l -main -go +

then open http://localhost:8080 in a browser. The + turns on debug mode so you get a REPL alongside the running server. Use pil health.l -main -go -wait for normal running.

-main and -go are just function calls from the command line: a leading - evaluates (main) and (go). The database file health.db is created on first use.

Running it for real in 2026

Common misconceptions

How it connects

Last edited · 5 revisions

Tags: #Computing