[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: User-defined record types
From: |
Stefan Monnier |
Subject: |
Re: User-defined record types |
Date: |
Wed, 15 Mar 2017 23:05:13 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
>> However, there is still EIEIO which may well need some expert guidance
>> to update.
> I can take care of that. Can you put your code on a branch like
> scratch/record?
OK, it's not working.
I found a problem with cl-defstruct objects, tho:
We're going to have trouble preserving backward compatibility with
pre-existing .elc files. If you look at the macro expansion of current
cl-defstruct:
(macroexpand '(cl-defstruct (sm-test) a b))
=>
(progn
(defvar cl-struct-sm-test-tags)
(define-inline sm-test-p (x) (declare (side-effect-free error-free))
(inline-letevals (x)
(inline-quote
(and (vectorp #1=,x) (>= (length #1#) 3)
(memq (aref #1# 0) cl-struct-sm-test-tags)
t))))
(put 'sm-test 'cl-deftype-satisfies 'sm-test-p)
(define-inline sm-test-a #2=(x)
"Access slot \"a\" of `(sm-test)' struct CL-X."
#3=(declare (side-effect-free t))
(inline-letevals #4=(x)
(inline-quote
(progn
(or (memq (aref #5=,x 0) cl-struct-sm-test-tags)
(signal #6='wrong-type-argument (list 'sm-test . #7=(,x))))
(aref #8=,x 1)))))
(define-inline sm-test-b #2# "Access slot \"b\" of `(sm-test)' struct
CL-X." #3#
(inline-letevals #4#
(inline-quote
(progn
(or (memq (aref #5# 0) cl-struct-sm-test-tags)
(signal #6# (list 'sm-test . #7#)))
(aref #8# 2)))))
(defalias 'copy-sm-test (function copy-sequence))
(cl-defsubst make-sm-test
(&cl-defs (nil . #9=((cl-tag-slot) (a) (b))) &key a b)
"Constructor for objects of type `sm-test'."
(declare (side-effect-free t))
(vector 'cl-struct-sm-test a b))
(eval-and-compile
(cl-struct-define 'sm-test nil 'cl-structure-object 'nil nil '#9#
'cl-struct-sm-test-tags 'cl-struct-sm-test 't))
'sm-test)
As you can see, the code says it inherits from `cl-structure-object'
(which now is of `record` type), but its constructor `make-sm-test`
creates a vector rather than a record, so (cl-typep 'cl-structure-object)
will fail if it only considers `type-of'.
Even if we could arrange for cl-struct-define to override the
definition of make-sm-test, that wouldn't help with all the places
where make-sm-test has been inlined already.
[ Of course, the reverse could happen as well: a new struct type (using
`record` in its constructor) could inherit from a parent that's still
using `vector`. But I think we can arrange for that to happen only in
cases we don't care to support. ]
Stefan
- Re: User-defined record types, (continued)
- Re: User-defined record types, Lars Brinkhoff, 2017/03/14
- Re: User-defined record types, Stefan Monnier, 2017/03/14
- Re: User-defined record types, Lars Brinkhoff, 2017/03/14
- Re: User-defined record types, Stefan Monnier, 2017/03/15
- Re: User-defined record types, Lars Brinkhoff, 2017/03/15
- Re: User-defined record types, Stefan Monnier, 2017/03/15
- Re: User-defined record types, Lars Brinkhoff, 2017/03/15
- Re: User-defined record types, Stefan Monnier, 2017/03/15
- Re: User-defined record types, Lars Brinkhoff, 2017/03/15
- Re: User-defined record types, Stefan Monnier, 2017/03/15
- Re: User-defined record types,
Stefan Monnier <=
- Re: User-defined record types, Stefan Monnier, 2017/03/15
- Re: User-defined record types, Lars Brinkhoff, 2017/03/16
- Re: User-defined record types, Stefan Monnier, 2017/03/16
- Re: User-defined record types, Lars Brinkhoff, 2017/03/17
- Re: User-defined record types, Lars Brinkhoff, 2017/03/17
- Re: User-defined record types, Stefan Monnier, 2017/03/18
- Re: User-defined record types, Stefan Monnier, 2017/03/18
- Re: User-defined record types, Lars Brinkhoff, 2017/03/19
- Re: User-defined record types, Stefan Monnier, 2017/03/19