[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
DEFSTRUCT and PASCAL-type Record Variants
- To: L.DIS[1,GLS]:
- Subject: DEFSTRUCT and PASCAL-type Record Variants
- From: GLS at SU-AI (Guy Steele)
- Date: Mon, 3 Jul 78 23:42:00 GMT
- Original-date: 3 Jul 1978 1642-PDT
It would be nice if the DEFSTRUCT hack had a provision
for handling PASCAL-type "record variants" (I have an
application for them). In this, one field of the structure
is a datum whose value determines the format of the rest
of the structure. Thus, in my application, one might
want to write something like
(DEFSTRUCT CODENODE ()
SEXPRCODE
ENVIRONMENT
(FUNNY-BITS 0)
(VARIANT NODETYPE
(VARIABLE VARTYPE VARNAME)
(CONSTANT CONSTVAL)
(SETQ VARTYPE VARNAME SETQBODY)
(LAMBDA LAMBDAVARS (REGISTERS '()) LAMBDABODY)
...))
That is, the VARIANT clause defines a field NODETYPE
whose value can be one of VARIABLE, CONSTANT, SETQ, LAMBDA, ...
Is is illegal to SETF this field, and its value must be specified
to MAKE-CODENODE when a CODENODE is created. Interpretively,
at least, SETF could test when altering a field, and access macros
could test when accessing, that the structure is of the right variant
form for that field to exist. PASCAL does not permit two variants
to have the same field name (as VARTYPE and VARNAME in my example);
it would be much hairier, but convenient, for DEFSTRUCT to check
for this and ensure that fields with the same name occupied the
same slot in all variants; in this manner if one knew that a
CODENODE was either a SETQ or a VARIABLE variant, then accessing
VARTYPE would work properly no matter which variant it were.
-------