LISP‎ > ‎

Objects

Historically, LISP first introduced structures (a kind of records), through the defstruct macro. Until then, LISPers used to implement specialized structures as lists of specific length, defining slot accessors as functions with meaningful names, such as person-name, person-age, person-sex, rather than using meaningless functions such as car, cadr, caddr. They eventually defined a defstruct macro providing the automatic generation of a constructor and accessors. Today, defstruct is considered as a little outdated: it is superseded by CLOS.

CLOS
The Common LISP Object System is a very sophisticated object oriented programming language, featuring multiple inheritance, multi methods, and complex schemes for combining methods. Method definition applies to basic types (such as numbers, strings or lists) considered as classes, as well as user defined classes. CLOS is certainly too rich for practical purposes.

defcl Module
This is a very tiny subset of CLOS, featuring
  • defcl macro: a simplified version of defclass, with two main restrictions, single inheritance and no slot modifiers (in agreement with purely functional programming, which bans the use of side effects);
  • new macro: provides a synonymous of make-instance.
The defcl module thus only deals with classes and objects, not with methods.

Remark: regarding Flow Game project, students are invited to stick to classical functional programming, augmented with defcl objects and classes, and discard method definition tools (defmethod and defgeneric), with the exception of print-object methods, which are extremely useful for debugging purposes (see Tulisp example).

Downloading and Playing with defcl.lisp Module Source File
You can download the defcl.lisp module, also available on ENSEIRB-MATMECA servers, see


to play with it, and evaluate the commented out examples.

Using Compiled defcl Module from its Installation Directory 
You can use the compiled version of defcl directly from its Tulisp installation directory (without copying anything). Assuming your project directory is <student-project>, add symbolic links to Tulisp installation directory and sbcl.lisp module:
cd <student-project>
ln -s /net/orge/ens/gloess/public_html/enseignement/CL/2010_2011/TP/tulisp/ tulisp
ln -s tulisp/sbcl.lisp sbcl.lisp
You should insert LISP directives for loading defcl at the beginning of your LISP module, right after the in-package declaration (normally the first form in your LISP file):

(in-package :common-lisp-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
  (require "SBCL" "sbcl"))    ; boot strap!

(eval-when (:compile-toplevel :load-toplevel :execute)
  (with-application-directory (:RELATIVE "tulisp") ; directory location.
    (sbcl-require "DEFCL" "defcl")))               ; require defcl.
Comments