Chapter 7
LAML

Kurt Nørmark
Department of Computer Science, Aalborg University, Denmark


Abstract
Previous lecture Next lecture
Index References Contents
In this side track lecture we will introduce the LAML system, which allows us to do web programming Scheme and in the functional programming paradigm


An Introductory LAML Example

HTML documents in LAML
Slide Annotated slide Contents Index
References Textbook 

We introduce LAML by studying the LAML counterpart of a very simple HTML document

Program: A very simple HTML document that illustrates the overall HTML document structure. It may, however, be tedious to write these tags for each and every small HTML page you have to produce.
<html>
   <head> 
     <title>This is the document title</title>
   </head>
   <body>
      <h1>Document title</h1>
      <p>Here is the first paragraph of the document</p>
      <p>The second paragraph has an <em>emphasized item</em>
         and a <b>bold face item</b>.
      </p>
   </body>
</html>

Program: The same document as an LAML expression. We see that the the shift from HTML to LAML is a matter of a few changes, some of which can be claimed to be of lexcical nature, and some of which are of concrete syntactical of nature. Notice the use of the underscore character, which suppresses the insertion of white space. This document cannot be processed immediately. However, the next version that we show can be processed.
(html
 (head 
  (title "This is the document title")
 )

 (body 
  (h1 "Document title")

  (p "Here is the first paragraph of the document")

  (p "The second paragraph has an" (em "emphasized item")
      "and a" (b "bold face item") _ ".")
  )
)

Program: The document from above embedded in the LAML framework. Besides initial loading, we see the imperative writing of the functionally generated document to a specific target file. If the source file is doc1.laml, the target file will be doc1.html.
(load (string-append laml-dir "laml.scm"))
(style "simple-html4.01-transitional-validating")

(write-html '(raw prolog epilog)
 (html
  (head 
   (title "This is the document title")
   )

  (body 
   (h1 "Document title")

   (p "Here is the first paragraph of the document")

   (p "The second paragraph has an" (em "emphasized item")
      "and a" (b "bold face item")_".")
   )
  )
)     

References


Programmatic Authoring

Authoring of web materials
Slide Annotated slide Contents Index
References Textbook 

Several different approaches to web authoring can be identified

  • Writing the document in a markup language

    • HTML - low level and non-extensible

    • XML - requires subsequent transformations or specification of the document rendering

  • Using a visual tool - a structure editor on top of the markup language

    • Good for low skill users

    • Difficult to manage large and complex materials

  • Transforming the document from another format

    • Will often result in a web edition of a paper document

    • Difficult to make effective use of the WWW's hypertext potentials

  • Writing the document in a programming language

    • Potentially good for users with programming skills

    • To be explored in this lecture

Programmatic authoring
Slide Annotated slide Contents Index
References Textbook 

The concept Programmatic authoring: Using programmatic authoring the document source is a program written in a programming language. By executing the program, the document source program is transformed to another format, typically HTML.

  • Expected advantages of programmatic authoring

    • We can use all the 'programming tricks' in the web authoring area

      • Authoring of complex materials parallels creation of non-trivial programs

    • Programmatic authoring is probably not feasible in many main stream languages

      • Java, C++, C, Pascal, Perl, ...

Using programmatic authoring the power of a programming language is available everywhere in the document, and at any time in the authoring process


LAML basics

LAML: Lisp Abstracted Markup Language
Slide Annotated slide Contents Index
References Textbook 
We now introduce the LAML system, which basically is Scheme with access to libraries which mirror HTML. In addition, we support a number of functions which in our experience are very helpful during a typical web authoring process. Some of these functions are organized in document styles, others in tools of various kinds.

The concept LAML: LAML means Lisp Abstracted Markup LanguageLAML provides abstractions, in terms of functions, for HTML. Beyond these it is possible to create arbitrary abstractions, along the line of XML.

  • LAML fundamentals:

    • The Scheme programming language itself

    • Mirrors of HTML and XML languages in Scheme

    • A number of useful libraries

    • A number of LAML document styles

    • A number of LAML tools

    • An Emacs Environment for practical use of LAML

LAML = Scheme + The HTML and XML mirrors


HTML mirror functions in LAML

The HTML mirrors in LAML
Slide Annotated slide Contents Index
References Textbook 
We will here describe the HTML4.01 transitional and the XHTML mirrors in LAML. All the essential observations also hold for XML-in-LAML languages. The XHTML mirrors are made via the XML-in-LAML framework.

The concept HTML mirror in Scheme: A HTML mirror in Scheme is a set of functions that in an accurate way makes the HTML elements of a particular HTML version available in Scheme

  • A one-to-one mapping of HTML elements to named functions in Scheme

  • Generates well-formed and valid HTML documents

  • Prevents accidental emission of '<', '>', and '&' as part of the textual contents

  • The mirror functions return abstract syntax trees which can be rendered as 'HTML text'

  • Supports optional pretty printing of the resulting HTML code

Not too many functions - not too few. You cannot by accident use a non-standard HTML element

Mirroring of HTML (1)
Slide Annotated slide Contents Index
References Textbook 

Program: A HTML mirror expression with attribute names (symbols), attribute values (strings following symbols) and content strings.
(f 'a1 "v1" 'a2 "v2" "Some text." "More text")

Program: The rendering of the value of the HTML mirror expression.
<f a1="v1" a2="v2"> Some text. More text</f>

The mirror function f distinguishes between attribute names, attribute values, explicit white space,character references,and content strings via the runtime types of the parameters together with their mutual position in the parameter list.

Mirroring of HTML (2)
Slide Annotated slide Contents Index
References Textbook 

Instead of specifying where to add white spaces we tell where to suppress it

Program: An HTML mirror expression which suppresses white space in front of punctuation characters.
(p "Use" (kbd "HTML") _ ","  (kbd "XHTML") _ ","
        (kbd "XML")_ "," "or" (kbd "LAML") _ ".")

Program: The rendering of the value of the HTML mirror expression.
<p>
  Use <kbd>HTML</kbd>, <kbd>XHTML</kbd>, <kbd>XML</kbd>, or <kbd>LAML</kbd>.
</p>

Mirroring of HTML (3)
Slide Annotated slide Contents Index
References Textbook 

List of contents and lists of attributes are processed recursively and spliced together with their context

Program: An HTML mirror expression in which lists are passed as parameters to the HTML mirror functions.
  (body

    (ul 
      (map li (list "one" "two" "three"))
    )

    
    (let ((attributes
           (list 'start "3" 'css:list-style-type "lower-roman"))
          (contents (map li (list "one" "two" "three"))))
       (ol 'id "demo" contents attributes)))    

Program: The rendering of the value of the HTML mirror expression.
<body>
    <ul><li>one</li> <li>two</li> <li>three</li></ul>
       
    <ol style="list-style-type: lower-roman;" id="demo" start="3">
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ol>
</body>

Mirroring of HTML (4)
Slide Annotated slide Contents Index
References Textbook 

CSS attributes and HTML attributes are uniformly specified

CSS attributes are prefixed with css:

Program: An HTML mirror form in which we highlight a CSS attribute.
(em 'css:background-color "yellow" "Functional Programming in Scheme")

Program: The rendering of the value of the HTML mirror expression.
<em style="background-color: yellow;">Functional Programming in Scheme</em>

Summary of Mirror Rules
Slide Annotated slide Contents Index
References Textbook 

The HTML mirror conventions of LAML can be summarized in six rules

  • Rule 1
    An attribute name is a symbol in Scheme, which must be followed by an expression of type string, which plays the role as the attribute's value.

  • Rule 2
    Parameters which do not follow a symbol are content elements (strings or instances of elements).

  • Rule 3
    All content elements are implicitly separated by white space.

  • Rule 4
    A distinguished data object (the boolean value false) which we conveniently bind to a variable named _ suppresses white space at the location where the value appears.

  • Rule 5
    Every place an attribute or a content element is accepted we also accept a list, the elements of which are processed recursively and unfolded into the result.

  • Rule 6
    An attribute with the name css: a refers to the a attribute in CSS.


Practical LAML Work

LAML document processing
Slide Annotated slide Contents Index
References Textbook 

The LAML system supports a number of different ways to process a document

  • From the command prompt (shell)

    • Good for some Unix users

    • Good for tool composition - piping

  • From a Scheme prompt (LAML prompt)

    • Makes it possible to interact with LAML at a more fine grained level

  • From Emacs

    • Direct support of LAML from an advanced text editor

    • Synchronous and asynchronous processing

    • Keyboard shortcuts, templates, and menu support

    • Support of embedding of a substring in a Lisp form - and the inverse unembedding

The Emacs support of LAML can be seen as powerful environment for programmatic authoring

LAML document styles and tools
Slide Annotated slide Contents Index
References Textbook 

A number of document styles and tools have been built on top of the basic LAML libraries and the mirrors

  • Document styles

    • Domain specific web languages

    • LENO in which this material is written

    • Course plan in which the course home page is written

    • The Manual document style in which the LAML software is documented

    • ...

  • Tools

    • The Scheme Elucidator used to explain programs in this material

    • Web Calendar used on the course home page

    • XML parser and XML mirror generation tool

    • ...

LAML server-side programming - CGI
Slide Annotated slide Contents Index
References Textbook 

A number of non-trivial server side web systems have been made in LAML via use of CGI

  • LAML Web System

    • IDAFUS - a distance education manager used for CS open university activities during three years

    • The calendar manager

    • The exercise manager

    • ...

An example of CGI Programming in Scheme with LAML
Go to elucidatorAn example of CGI Programming in Scheme with LAML
Reference


XML-in-LAML

XML in LAML
Slide Annotated slide Contents Index
References Textbook 

XML-in-LAML is a mirroring technique that makes XML languages available in Scheme

  • XML-in-LAML

    • Mirror derivation from Document Type Definitions (DTDs)

    • Automatic derivation of validation predicates

    • Two or more XML languages can co-exist

  • Existing XML-in-LAML languages

    • XHTML (strict, transitional, frameset) with full validation

    • SVG - Scalable Vector Graphics - with partial validation

    • LENO - the XML language used as the source of this material - with full validation

    • Course Plan - the course home page system.

    • Program Dissection - A simple program explanation facility

    • Photo Show - A web photo presentation system


More info about LAML

More information
Slide Annotated slide Contents Index
References Textbook 

There are a number of sources to more information about LAML

  • Academic

    • The papers available from the LAML Home Page

  • Tutorial

    • The elucidative LAML Tutorial

  • LAML user/programmer information

    • The LAML software home page

LAML can be downloaded as free software from the LAML home page

References


Exercises

Exercises
Slide Annotated slide Contents Index
References 
Here we propose exercises related to LAML

Exercise 7.2. Bookmark administration

Exercise motivation: It is not practical to bind web bookmarks to a single machine nor to a single browser. Therefore we will maintain a list of bookmark entries in a file, and generate web bookmark pages from this description.

We will assume that we maintain a list of bookmark entries, each of the form

(bookmark URL title category comment)

The first constituent is a symbol (a tag that distinguishes bookmark entries from other structured data) and the other fields are text strings.

You can find an example of a bookmark list here. See the link in the web version.

The exercise is to complete a frame-based bookmark browser, given a list of bookmarks.You can find an example of a frame-based bookmark browser here. See again the link in the web version. To make it realistic for you to solve this exercises, you are only asked to make the left frame: the category overview frame. The frameset page and the right frame page are already programmed.

You are, however, supposed to understand the pre-programmed frame of the exercise. So start to read through the existing pieces of the program.

You can find the pre-programmed part of the bookmark browser in the zip file bookmarks-zip.zip. Please consult the web version of the material to get access to it. Unzip it, and LAML process the file bookmark.laml. Bring up the file bookmark-frameset.html in a browser to get started.

You are welcome to extend the solution, for example with a good use of the comment field from the bookmark entry.


Collected references
Contents Index
The LAML generated document as rendered in a browser
The initial HTML document as rendered in a browser
The authors personal LAML calendar
The LAML software home page - development version
The LAML tutorial
The LAML home page

 

Chapter 7: LAML
Course home     Author home     About producing this web     Previous lecture (top)     Next lecture (top)     Previous lecture (bund)     Next lecture (bund)     
Generated: July 2, 2013, 09:15:59