From: Karol Skocik
Subject: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <e51c53ea-7c23-4ee4-a6b4-3595d68e1372@v15g2000yqn.googlegroups.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?

Karol

From: budden
Subject: Re: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <7d9ab6af-aeeb-4721-bd0a-412b90051987@t11g2000yqg.googlegroups.com>
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.
From: budden
Subject: Re: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <eae5d644-f53b-4af8-994a-da108e7f5f21@k41g2000yqn.googlegroups.com>
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.
From: Karol Skocik
Subject: Re: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <92381802-fa60-465b-a4ea-255a49c5ba07@p2g2000prn.googlegroups.com>
On Dec 5, 8:12 pm, budden <········@gmail.com> wrote:
> 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.

I think SBCL has something like sb-vm::map-allocated-objects...
From: budden
Subject: Re: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <09033a7e-c942-4f31-a01a-014fa58fcaae@r40g2000yqj.googlegroups.com>
On 5 ÄÅË, 22:34, Karol Skocik <············@gmail.com> wrote:
> On Dec 5, 8:12špm, budden <········@gmail.com> wrote:
>
> > 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.
>
> I think SBCL has something like sb-vm::map-allocated-objects...
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.
From: budden
Subject: Re: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <aca9dcc3-3a29-4c62-92e7-bc1c36c5eac5@k19g2000yqg.googlegroups.com>
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.
From: Karol Skocik
Subject: Re: how to undefine structure and replace it with a class of the same 	name?
Date: 
Message-ID: <e54a2202-9078-4657-acae-b5469b167f84@j39g2000yqn.googlegroups.com>
On Dec 5, 7:46 pm, budden <········@gmail.com> wrote:
> 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.

uninterning seems like a good idea.
From: Stanisław Halik
Subject: Re: how to undefine structure and replace it with a class of the same ?name?
Date: 
Message-ID: <ghh0e2$18ir$3@opal.icpnet.pl>
thus spoke Karol Skocik <············@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
From: budden
Subject: Re: how to undefine structure and replace it with a class of the same 	?name?
Date: 
Message-ID: <af4ac6df-50a0-406b-a3b5-dbc0279666ab@h20g2000yqn.googlegroups.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)
-------------
Common Lisp freelancer for 4$/hour
From: Stanisław Halik
Subject: Re: how to undefine structure and replace it with a class of the same ??name?
Date: 
Message-ID: <ghlqki$k92$1@opal.icpnet.pl>
thus spoke budden <········@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.

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