Path: utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!yale!cmcl2!phri!marob!cowan From: cowan@marob.masa.com (John Cowan) Newsgroups: comp.lang.lisp Subject: Re: STRUCTUREP Message-ID: <2714943B.1332@marob.masa.com> Date: 11 Oct 90 15:48:11 GMT References: <753@forsight.Jpl.Nasa.Gov> <27133D6E.715C@marob.masa.com> <755@forsight.Jpl.Nasa.Gov> Organization: The Logical Language Group, Inc. Lines: 60 Erann Gat writes: [is there a STRUCTUREP in Common Lisp?] I write: [No; standard types can be implemented as structures] Erann replies: >Oh, come on! Since the implementation gets to define structurep, it >can make explicit checks to exclude other types which the implementation >implements as structures. It may not be pretty or efficient, but it's >certainly not impossible! The point is that the non-existence of STRUCTUREP allows freedom to the implementor to make certain choices. Structures are a "raw" construct in CL, with very few specific semantics (see below). >Suppose I >wanted to write a function that took an arbitrary structure and printed >out all the slot names and values. This can't be done in CL, but the >inspector can do it so the underlying capability must be there (at least >in every implementation I've ever used). This is another example of something >that can be done in T but not in CL. (BTW, this function might want to >be able to check that its argument was indeed a structure before proceeding.) The underlying capability is indeed there; however, the implementation is not required to expose it to the user in any systematic way that might constrain >how< this capability is provided. >It is >possible to implement a T-style structure system within Common Lisp. (The >details are left as an excercise for the reader.) Perhaps structurep will >appear in CLTL3. Not only do I know it's possible, I've actually done it. I have a nearly- complete implementation of T3.0 written in Common Lisp (1st ed.). T structures are all instances of a single CL structure type, T::STRUCT, which uses an auxiliary CL structure T::STYPE to hold T-structure-type meta-information. My point is that Common Lisp structures >aren't< T structures, and aren't meant to be. CL structures are a layer of syntactic sugar that allow you to define handy {access, construct, print} functions, and take care of some of the work. The underlying datatype can be a list, a vector, or a MacLisp hunk (i.e. a cons with != 2 components). The "hunk-level" access provided in MacLisp is not standardized by CL, so you can't reliably get at it, and implementers who think they can do better than hunks are free to do so. CL is not designed to require retaining any meta-information at run time about structures, except for what is needed by debugging tools (inspector, etc.) whose interfaces are not standardized. T structures, OTOH, are much more abstract, with considerable meta-information, more like T objects. In fact, we can say that structures only exist in T as a way of making certain kinds of rather "passive" objects more efficient. -- cowan@marob.masa.com (aka ...!hombre!marob!cowan) e'osai ko sarji la lojban