Next: 8.2 Alien Types
Up: 8 Alien Objects
Previous: 8 Alien Objects
Because of Lisp's emphasis on dynamic memory allocation and garbage
collection, Lisp implementations use unconventional memory representations
for objects. This representation mismatch creates problems when a Lisp
program must share objects with programs written in another language. There
are three different approaches to establishing communication:
- The burden can be placed on the foreign program (and programmer) by
requiring the use of Lisp object representations. The main difficulty with
this approach is that either the foreign program must be written with Lisp
interaction in mind, or a substantial amount of foreign ``glue'' code must be
written to perform the translation.
- The Lisp system can automatically convert objects back and forth
between the Lisp and foreign representations. This is convenient, but
translation becomes prohibitively slow when large or complex data structures
must be shared.
- The Lisp program can directly manipulate foreign objects through the
use of extensions to the Lisp language. Most Lisp systems make use of
this approach, but the language for describing types and expressing
accesses is often not powerful enough for complex objects to be easily
manipulated.
CMU Common Lisp relies primarily on the automatic conversion and direct manipulation
approaches: Aliens of simple scalar types are automatically converted,
while complex types are directly manipulated in their foreign
representation. Any foreign objects that can't automatically be
converted into Lisp values are represented by objects of type
alien-value. Since Lisp is a dynamically typed language, even
foreign objects must have a run-time type; this type information is
provided by encapsulating the raw pointer to the foreign data within an
alien-value object.
The Alien type language and operations are most similar to those of the
C language, but Aliens can also be used when communicating with most
other languages that can be linked with C.
Next: 8.2 Alien Types
Up: 8 Alien Objects
Previous: 8 Alien Objects
Raymond Toy
Mon Jul 14 09:11:27 EDT 1997