guile-devel
[Top][All Lists]
Advanced

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

Re: make-vtable


From: Ludovic Courtès
Subject: Re: make-vtable
Date: Tue, 13 Feb 2007 09:13:17 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Hi,

Kevin Ryde <address@hidden> writes:

> I made a bit of a start trying to improve the structures section of
> the manual, I always found it pretty hard to follow.  One big
> stumbling block for me was vtables, but I now see if you want to make
> a struct you have to make a vtable vtable, and from that a vtable, and
> only then your struct.  Seems hard work for casual users, if you're
> not (at first) interested in that second level of "type of type".

My understanding (which might be inaccurate) is that there is in fact no
such three-level indirection: in classic reflective OO terms,
`make-vtable-vtable' returns a "class" object which `make-struct' can
then use to return regular (i.e., non-class) objects.  In particular,
this example (from `structs.test') works:

     (let* ((vtable (make-vtable-vtable "pr" 0))
            (s1     (make-struct vtable 0 "hello"))
            (s2     (make-struct vtable 0 "hello")))
       ;; S1 and S2 are both "regular" one-field structs.
       (equal? s1 s2))

So I think it's even more confusing than it seems.  ;-)

I'd say that `make-vtable-vtable' is inappropriately named and should
really be `make-vtable'.  Does that make sense?

(Not to mention that the primary use of the term "vtable" is for
_method_ pointers in C++, which definitely has nothing to do with this.)

> How about something like this to just make a vtable from fields and
> optional printer func,
>
>     (define (make-vtable fields . print)
>       (apply make-struct (make-vtable-vtable "" 0) 0
>              (make-struct-layout fields)
>              print))

IIUC, `(define make-vtable make-vtable-vtable)' should suffice.

Thanks,
Ludovic.




reply via email to

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