guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: goops proposal: proper struct classes


From: Andy Wingo
Subject: Re: goops proposal: proper struct classes
Date: Thu, 05 May 2011 20:25:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi :)

On Thu 05 May 2011 18:35, address@hidden (Ludovic Courtès) writes:

> Andy Wingo <address@hidden> writes:
>
>> If you know GOOPS, then you know that we have classes, rooted at
>> <class>.  And indeed <class> shows up a lot in documentation and in
>> code.  But that's not how it is in CLOS: our <class> corresponds to
>> their `standard-class'.  They have a superclass, called `class', which
>> is the real root, and from which e.g. structure classes are derived.
>>
>> We need to do this.  Currently, class-of on a struct/record data type
>> gives a useless class that can't instantiate instances, doesn't know its
>> slots, and does not reflect the vtable hierarchy.
>
> Here’s an illustration:
>
> scheme@(guile-user)> (use-modules (oop goops) (srfi srfi-9))
> scheme@(guile-user)> (define-record-type <foo> (make-foo x) foo? (x foo-x))
> scheme@(guile-user)> (make-foo 2)
> $3 = #<<foo> x: 2>
> scheme@(guile-user)> (class-of $3)
> $4 = #<<class> <> 148a4b0>

Here it probably should have a name, even now; probably a bug, that
srfi-9 should call set-struct-vtable-name! on the rtd.

> scheme@(guile-user)> (class-slots $4)
> $5 = ()
> scheme@(guile-user)> (class-of $4)
> $6 = #<<class> <class> 8e7a50>

Here's the problem, for me: 

    scheme@(guile-user)> (define-record-type <foo> (make-foo x) foo? (x foo-x))
    scheme@(guile-user)> (make-foo 10)
    $1 = #<<foo> x: 10>
    scheme@(guile-user)> (struct-vtable $1)
    $2 = #<vtable:2356fa0 pruhsruhpwphuhuh 6a55640>
    scheme@(guile-user)> (struct-vtable $2)
    $3 = #<vtable:2356fa0 pruhsruhpwphuhuh 2356fa0>
    scheme@(guile-user)> (struct-vtable $3)
    $4 = #<vtable:2356fa0 pruhsruhpwphuhuh 2356fa0>

See?  The struct's vtable is actually an instance of another vtable --
of another class -- and that metaclass is a vtable-vtable (because $3
and $4 are equal).

So class-of $2 should yield the class-of $3, which is actually some
other bug:

    scheme@(guile-user)> (class-of $2)
    $5 = #<<class> <> 368e870>
    scheme@(guile-user)> (class-of $3)
    $6 = #<<class> <> 368e870>

>> So we need a <basic-class>, interposed between <class> and <object>,
>> which will be the real root of our class meta-object hierarchy.
>
> Why?
>
> Couldn’t ‘scm_i_define_class_for_vtable’ build a full-blown class,
> populating its CPL, its ‘slots’ slot, etc.?

Yes, it could.  I didn't mention that.  I think that such a duplicate
hierarchy is unnecessary, because we can define methods for some of the
class protocol (class-name at least!).

Vtables *are* classes, on a fundamental level.  Bare vtables are not as
nice as <class>, but they do describe instances.  SCM_CLASS_OF() is
SCM_STRUCT_VTABLE().

WDYT?  Am I off the deep end again? :)

Andy
-- 
http://wingolog.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]