PicoLisp Form Library

mattias@inogu.se

Perfection is attained
not when there is nothing left to add
but when there is nothing left to take away
(Antoine de Saint-Exupéry)

# The PicoLisp Form Library

(c) Software Lab. Mattias Sundblad

This document describes the form library included with the PicoLisp system.

The purpose of this document is to go into the form library in more depth and hopefully supply an overview of the various components involved.

This document builds upon the information provided in Application Dev. Please start by going through this section of the documentation.

Also remember to take a look at the PicoLisp Tutorial for an explanation of some aspects of PicoLisp, and scan through the list of Frequently Asked Questions (FAQ).

## A typical example

A typical usage of forms and form components can be found in the example application included with the PicoLisp distribution. This application has a number of search forms in app/gui.l and forms to display and edit objects, for example app/cusu.l.

Let's have a look at app/cusu.l. This file displays and allows you to edit objects of the class +Cusu (Customer/ Supplier, defined in app/er.l). The beginning of this file looks like this:

    ########################################################################
    (must "Customer/Supplier" Customer)

    (menu ,"Customer/Supplier"
       (idForm ,"Customer/Supplier" '(choCuSu) 'nr '+CuSu T '(may Delete)
          '((: nr) " -- " (: nm))
          ....
    ########################################################################

The first line checks whether the user has the right permissions to access this page. After that a call to a function called 'menu' follows. This function is defined in app/gui.l and creates the menu and basic page layout of this application. Nested within the call to 'menu' is our first, direct encounter with a form function. In this case it is a call to 'idForm'. Let us look a little closer at this call.

The first parameter, "Customer/Supplier", is used in the form heading. Parameter number two is interesting. '(choCuSu) creates a dialog that makes is possible to search for an existing object to display/ edit, or create a new one. The function 'choCuSu'is defined in app/gui.l and uses another form function, called 'diaForm'. An abbreviated version is shown below.

    ########################################################################
    (de choCuSu (Dst)
       (diaform '(Dst)
          (<grid> "--.-.-."
             # Form components
             ... )
          (gui 'query '(+QueryChart) (cho)
             # Pilog query
             9
             '((This) (list This (: nr) This (: nm2) (: em) (: plz) (: ort) (: tel) (: mob))) )
          (<table> 'chart (choTtl ,"Customers/Suppliers" 'nr '+CuSu)
             # Table headers
             (do (cho)
                (<row> (alternating)
                   (gui 1 '(+DstButton) Dst)
                   ...
                   (gui 9 '(+TelField)) ) ) )
          (<spread>
             (scroll (cho))
             (newButton T Dst '(+CuSu) ...)
             (cancelButton) ) ) )
    ########################################################################

As can be seen in app/gui.l, the search dialogs contain a lot of functionality. This is quite typical. 'choCuSu' starts off by calling 'diaform'. This function is used when we want a form to behave in a similar way to a dialog (See Alerts and Dialogs for a description of how dialogs work in the framework). The first part of our diaform is a 'grid' containing some form components. See application development for a more thorough description of form components.

The grid is followed by another gui component, this time a +QueryChart. The chart is an interesting, and very useful concept. The basic idea is to separate how data is presented in the gui from the internal representation. See charts for more information.

The +QueryChart has a Piloq query used to fetch the data we want to show from the database. This part is followed by a number, in this case 9, which tells the Chart how many columns of data to expect. The last part is a function that takes care of putting data into the chart gui from the dataset retrieved by the Pilog query.

Finally, a table is used to present the result. The number of columns in this table must match the number mentioned above, the one that tells the chart how many columns to expect.

What is described in the preceding section is a common way of structuring applications in PicoLisp. The objects are displayed and edited using idForms, which use diaforms to select or create new objects to view or edit. Please take some time to study the demo app included with the distribution. Another good idea is to start experimenting with some small application of your own. It is a very good way to get acquainted with the language and framework, and I highly recommend it! One way to do that would be to start making changes to the demo application. Just copy it to a directory of your choice and start exploring. It really is a lot of fun!

## Form Library Function Reference

This section provides a reference manual for the form library functions. See the thematically grouped list of indexes below.

Though PicoLisp is a dynamically typed language (resolved at runtime, as opposed to statically (compile-time) typed languages), many functions can only accept and/or return a certain set of data types. For each function, the expected argument types and return values are described with the following abbreviations:

The primary data types:

- `num` - Number
- `sym` - Symbol
- `lst` - List

Other (derived) data types

- `any` - Anything: Any data type
- `flg` - Flag: Boolean value (`NIL` or non-`NIL`)
- `cnt` - A count or a small number
- `dat` - Date: Days, starting first of March of the year 0 A.D.
- `tim` - Time: Seconds since midnight
- `obj` - Object/Class: A symbol with methods and/or classes
- `var` - Variable: Either a symbol or a cons pair
- `exe` - Executable: An executable expression (`eval`)
- `prg` - Prog-Body: A list of executable expressions (`run`)
- `fun` - Function: Either a number (code-pointer), a symbol (message) or a list (lambda)
- `msg` - Message: A symbol sent to an object (to invoke a method)
- `cls` - Class: A symbol defined as an object's class
- `typ` - Type: A list of `cls` symbols
- `pat` - Pattern: A symbol whose name starts with an at-mark "`@`"
- `pid` - Process ID: A number, the ID of a Unix process
- `tree` - Database index tree specification
- `hook` - Database hook object

Arguments evaluated by the function (depending on the context) are quoted (prefixed with the single quote character "`'`").

A B C D E F G H I J L M N O P Q R S T U V Y

Forms
  `diaform form idForm`
Utility functions
  `action alternating change chart cho choTtl curr disable error expires field <id> newUrl prev row *Throbber url`
Button functions
  `saveButton closeButton okButton cancelButton choButton delButton yesButton noButton editButton searchButton resetButton newButton cloneButton`
Alerts and dialogs
  `dialog alert note ask choDlg`
Form field classes
  `+Auto +Button +BubbleButton +ClrButton +DelRowButton +DnButton +GoButton +UpButton +Drop +JS +OnClick +ShowButton +Checkbox +Radio +TextField +UndoButton +LinesField +ListTextField +PwField +UpField +RgbPicker +RedoButton +SymField +NumField +FixField +AtomField +DateField +TimeField +Img +Icon +FileField +Url +HttpField +MailField +TelField +SexField +JsField +BlobField +ClassField +DstButton +ChoButton +Choice +PickButton +InsRowButton`
Charts
  `+Chart +Chart1 +QueryChart`
Entity/ Relationship classes
  `+/R +E/R +SubE/R`
Base classes
  `+gui +field +obj +hint`
Prefix classes
  `+Align +AO +Chg +Clr0 +Dflt +Edit +Enum +Force +Obj +ObjView +ObjVal +Var +Cue +Trim +Uppc +Lowc +Rid +Set +Sgn +Val +Fmt +Able +Lock +View +Upd +Chk +Limit +Init +Map +Tip +Focus +Mono +DbHint +Close +Click`
Styles and layouts
  `+Style +Tiny`

## Download

The `PicoLisp` system can be downloaded from the PicoLisp Download page.