Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to undefine structure and replace it with a class of the same name?

10 views
Skip to first unread message

Karol Skocik

unread,
Dec 5, 2008, 12:11:27 PM12/5/08
to
I know I could quit and start the system again but that seems too
unlispy. However, I don't know what should happen to already created
instances of structure?

Karol

budden

unread,
Dec 5, 2008, 1:46:06 PM12/5/08
to
Structures are not listable, as I know. So I think there is no way in
general to convert all structure instances to class instances. Cheaper
alternative to quitting might be uninterning all structure-related
functions. Structures already allocated will remain, but namespace is
cleaned, you can define the class with the "same" name.

If you can solve problem of enumerating structures in your image (or
do not really need to do so), it would be nice to have a general
function which returns at least some metadata of structure. Maybe this
can be done with inspector. E.g., SLIME source shows that structures
(at least some of them) may be converted to alist with

> (nth-value 2 (sb-impl::inspected-parts (make-xxx :yy 1))) ; where xxx is a defined structure
((YY . 1) (ZZ))
> (sb-impl::inspected-parts (find-class 'xxx))
shows structure class.

Hmm, I can see no conc-name here... I'm afraid it is not stored. To
fix this, you'll need custom version of defstruct which saves conc-
name somewhere.

Got no more time it now, but I'm sure if you make some portable code
to deal with structures, it will bring some glory for you (maybe this
is done already, but I don't know) and make a lisp better.

budden

unread,
Dec 5, 2008, 2:12:18 PM12/5/08
to
BTW, this looks like another... hole in an CL. In fact, here is a GC
which knows how to map over all live objects. I am sure Lisp might
have an interface to run a piece of code against every live object of
a given type.

Karol Skocik

unread,
Dec 5, 2008, 2:34:27 PM12/5/08
to

uninterning seems like a good idea.

Karol Skocik

unread,
Dec 5, 2008, 2:34:36 PM12/5/08
to

I think SBCL has something like sb-vm::map-allocated-objects...

budden

unread,
Dec 5, 2008, 3:09:31 PM12/5/08
to
Yeah, I just found it and wanted to suggest the following:

(defun collect-all-objects-of-type (type)
(assert (not (eq type 'cons)) () "unable to count conses as we're
collecting them to list. Collect conses to vector!")
(let (obj-list)
(loop for space in '(:static :dynamic :read-only)
do
(sb-vm::map-allocated-objects (lambda (o tag bytes)
(declare (ignorable tag bytes))
(when (typep o type)
(pushnew o obj-list)))
space))
obj-list))

But it does not solve your problem. You need collect and replace not
the structures themselves, but the _references_ to them. GC can do
this, while map-allocated-objects can't.

budden

unread,
Dec 6, 2008, 2:32:04 AM12/6/08
to
It looks like map-allocated-objects is not precise:
here is a comment near its definition.
;;; bytes, including any header and padding. CAREFUL makes
;;; MAP-ALLOCATED-OBJECTS slightly more accurate, but a lot slower: it
;;; is intended for slightly more demanding uses of heap groveling
I don't know what are the reasons for that, but I think we can't
really iterate
over all objects with it. I also unsure if it can map dynamic-extent
objects.

Stanisław Halik

unread,
Dec 7, 2008, 12:16:50 PM12/7/08
to
thus spoke Karol Skocik <Karol....@gmail.com>:

> I know I could quit and start the system again but that seems too
> unlispy. However, I don't know what should happen to already created
> instances of structure?

(setf (find-class 'some-struct) nil)

--
The great peril of our existence lies in the fact that our diet consists
entirely of souls. -- Inuit saying

budden

unread,
Dec 8, 2008, 11:08:16 AM12/8/08
to
> (setf (find-class 'some-struct) nil)
Wrong. Does not work at all in SBCL and Lispworks:
1. Structure constructior and slot accessors are not destroyed.
2. make-some-structure returns instance of a structure
3. (type-of (make-some-structure)) returns 'some-structure the same
thing it returned prior to
(setf (find-class 'some-struct) nil)
-------------
Common Lisp freelancer for 4$/hour

Stanisław Halik

unread,
Dec 9, 2008, 8:08:35 AM12/9/08
to
thus spoke budden <budd...@gmail.com>:

>> (setf (find-class 'some-struct) nil)
> Wrong. Does not work at all in SBCL and Lispworks:
> 1. Structure constructior and slot accessors are not destroyed.
> 2. make-some-structure returns instance of a structure
> 3. (type-of (make-some-structure)) returns 'some-structure the same
> thing it returned prior to
> (setf (find-class 'some-struct) nil)

Shouldn't pose a problem for the purpose of replacing a structure with a
class.

Hard to obliterate a structure completely due to accessors getting
inlined.

0 new messages