Lisp - Objects



LISP, is a very versatile and power language. LISP is a dynamically typed language meaning the type of object is determined at runtime and we are not bound to define type everytime we declare an object in LISP. In this chapter, we're discussing the objects, what constitutes them, what are their features in details.

Dynamically Typed

In LISP, object type is checked at runtime, making it a dynamically typed language. It provides developers a greater flexiblity. LISP provides various functions to check the type of the object. In case of structure created using defstruct, LISP generates methods to check the type of the structure automatically.

Built-in Data Types

LISP provides a rich set of fundamental data types which are considered as objects.

  • numbers like integer, float, etc.

  • symbols like backquote, comma etc.

  • string

  • list

  • array

  • and many more.

CLOS, Common LISP Object System

CLOS, is a object oriented programming system, an integral part of Common LISP. CLOS provides a powerful and flexible system to define and manipulate objects in LISP. Objects are instances of a Class in CLOS.

Aspects of Objects in CLOS

  • Class − A class defines the structure and behavior of an object.

  • Instance − An instance represent the implementation of a class.

  • Slot − Attributes of objects are termed as slots.

  • Generic Function − Define the behavior of the object although generic functions are not part of class definition.

  • Multimethod − A multimethod can change behavior based on types of arguments passed.

  • Multiple Inheritance −CLOS class can inherit attributes of multiple superclasses.

Considerations on LISP Objects

  • Flexibility − LISP objects are highly flexible. We can change type of an object at runtime and perform other relevant modifications.

  • Power of CLOS − CLOS adds multiple inheritance, multimethods supports to LISP objects.

Conclusion

LISP considers fundamental data types as objects and treats them in similar fashion as more structured objects in CLOS. LISP dynamic nature, adds extensibility and gives developer flexibility to write natural code in an easier way .These capabilities of LISP makes it a very powerful and flexible programming language.

Advertisements