Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'Expressions, Types, and Functions
3.  Lisp and Scheme

We use the programming language Scheme in this material. Therefore it is natural to start with a brief discussion of the family of languages, to which Scheme belongs. This is the Lisp family of languages.

3.1 Lisp3.2 Scheme
 

3.1.  Lisp
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

Lisp was invented by John McCarthy in the late fifties. In these days the dominating use of computers was for numeric purposes. One of the purposes of Lisp was to support symbolic computation.

As an example of symbolic computation, let us mention the calculation of differentiated mathematical functions. The symbolic derivation of the function f(x) = x * x is the function g(x) = 2 * x. The numeric derivation of f will never deliver the function g on source form. The best we can hope for is some sort of numeric approximation to g, which can be applied to numbers.

It is worth noticing that transformation and compilation of programs also can be considered as symbolic computations. In fact it turns out, that the computer is better suited to do symbolic computations than numeric computations, because the former always can be done exactly, whereas the latter often are inexact.

Today, many Lisp languages are not in use any more. Lisp 1.5 and Interlisp are two of these. 'Lisp' is today used as a family name of all 'Lisp languages', which includes such languages and Emacs Lisp, Common Lisp, and Scheme.

Lisp is the next oldest programming language - only Fortran is older.

In the past, thousands of programming languages have been invented and tried out. Naturally, many of these are not in active use any more. It is interesting to notice that both Lisp and Fortran are still in widespread use for many different purposes.

Below we will summarize the main characteristics of Lisp.

  • Lisp characteristics:

    • Invented for symbolic computations

    • Superficially inspired by mathematical function theory

    • Is syntactically and uniformly based on parenthesized prefix notation

      • Parsing a Lisp program is trivial

    • Programming goes hand in hand with language development

    • It is easy to access and manipulate programs from programs

      • Calls for tool making in Lisp

One of the most remarkable facts of Lisp is that the primary data structure in the language - lists - is used for the representation of programs. This is the reason why we use all these parentheses in a Lisp program! Originally, this characteristic program representation was only thought as an intermediate representation, not to be used by the human programmer. It turned out, eventually, that the representation had some very useful properties. Therefore the following 'equation' is an important characteristic of all Lisp languages.

Program = Data = Lists

 

3.2.  Scheme
Contents   Up Previous Next   Slide    Subject index Program index Exercise index 

Scheme is a programming language in the Lisp family. Scheme is formally defined in the Scheme report [Abelson98], which is revised from time to time. Currently, the fifth revision is the most current one. This explains the abbreviation R5RS, which goes something like 'The fifth Revised Report on the Algorithmic Language Scheme'.

Scheme is a small, yet powerful language in the Lisp family

  • Scheme characteristics:

    • Supports functional programming - but not on an exclusive basis

    • Functions are first class data objects

    • Uses static binding of free names in procedures and functions

    • Types are checked and handled at run time - no static type checking

    • Parameters are evaluated before being passed - no lazyness

Many people encounter Lisp programming in Emacs Lisp [fsf02] , [fsf02a], because of the need of customizing Emacs in non-trivial ways. Emacs Lisp is an old and primitive dialect of Lisp. Hard core Lisp programmers are also likely to meet Common Lisp, which is much bigger than Scheme. The statement below compares very briefly Common Lisp and Emacs Lisp with Scheme.

Scheme is an attractive alternative to Common Lisp (a big monster) and Emacs Lisp (the rather primitive extension language of the Emacs text editor).


Exercise 2.1. Getting started with Scheme and LAML

The purpose of this exercises is learn the most important practical details of using a Scheme system on Unix. In case you insist to use Windows we will assume that you install the necessary software in your spare time. There is no time available to do that during the course exercises. Further details on installation of Scheme and LAML on Windows.

You will have to choose between DrScheme and MzScheme.

DrScheme is a user friendly environment for creating and running Scheme programs, with lots of menus and lots of help. However, it is somewhat awkward to use DrScheme with LAML. Only use DrScheme in this course if you cannot use Emacs, or if you are afraid of textually, command based tools. Follow this link for further details.

MzScheme is the underlying engine of DrScheme. MzScheme is a simple read-eval-print loop, which let you enter an expression, evaluate and print the result. MzScheme is not very good for debugging and error tracing. MzScheme works well together with Emacs, and there is a nice connection between MzScheme and LAML. MzScheme used with Emacs is preferred on this course. Please go through the following steps:

  1. Insert the following line in your .emacs file in your home dir, and then restart Emacs:

      (load "/pack/laml/emacs-support/dot-emacs-contribution.el")

  2. Have a session with a naked Scheme system by issuing the following command in Emacs: M-x run-scheme-interactively

    • Define a couple of simple functions ( odd and even, for instance) and call them.

    • Split the window in two parts with C-x 2 and make a buffer in the topmost one named sources.scm ( C-x b ). Bring the Scheme interpreter started above into the lower part of the window. The buffer with the Scheme process is called *inferior-lisp*. Put the sources.scm buffer in Scheme mode ( M-x scheme-mode ). Define the functions odd and even in the buffer and use the Scheme menu (or the keyboard shortcuts) to define them in the running Scheme process.

  3. Have a similar session with a Scheme+LAML system by issuing the following command in Emacs: M-x run-laml-interactively (You may have to confirm that a previously started Scheme process is allowed to be killed).

    • All you did in item 2 can also be done here.

    • Evaluate a simple HTML expression, such as

            (html (head (title "A title")) (body (p "A body")))

    • Use the function xml-render to make a textual rendering of the HTML expression.

    • Make a deliberate grammatical error in the LAML expression and find out what happens.

  4. Make a file 'try.laml'.

    • Control that Emacs brings the buffer in Laml mode. Issue a M-x laml-mode explicitly, if necessary.

    • Use the menu 'Laml > Insert LAML template' to insert an XHTML template.

    • Fill in some details in the head and body.

    • Process the file via the LAML menu in Emacs: Process asynchronously. The file try.html will be defined.

    • Play with simple changes to the HTML expression, and re-process. You can just hit C-o on the keyboard for processing.

    • You can get good inspiration from the tutorial Getting started with LAML at this point.

There is no solution to this exercise


 

3.3.  References
[Fsf02a]GNU Emacs Lisp Reference Manual. The Free Software Fundation Inc, May 2002.
[Fsf02]Free Software Foundation, "Programming in Emacs Lisp (Second Edition)", January 2002.
[Abelson98]Richard Kelsey, William Clinger and Jonathan Rees, "Revised^5 Report on the Algorithmic Language Scheme", Higher-Order and Symbolic Computation, Vol. 11, No. 1, August 1998, pp. 7--105.

Generated: Tuesday July 2, 2013, 09:14:49
Theme index -- Keyboard shortcut: 'u'  Previous theme in this lecture -- Keyboard shortcut: 'p'  Next slide in this lecture -- Keyboard shortcut: 'n'