* [GOOPS] make class-name a generic?
@ 2004-02-23 14:04 Andreas Rottmann
2004-02-23 20:25 ` Mikael Djurfeldt
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Rottmann @ 2004-02-23 14:04 UTC (permalink / raw)
Hi!
In my code, I define a method on class-name. Since (oop goops) defines
this as a simple procedure, I have to export the generic in my module,
which leads to annyoing warnings about duplicate imports which are
superfluous because the original class-name is still "there", just as
a generic default method. Sample code:
(define-module (foo)
#:use-module (oop goops)
#:export (<foo> class-name))
(define-class <foo> ()
(class-name #:getter class-name #:init-value 'foobar))
(define-module (bar)
#:use-module (oop goops)
#:use-module (foo))
(format #t "class-name of <foo> instance: ~S\n"
(class-name (make <foo>)))
(format #t "class-name of <foo>: ~S\n" (class-name <foo>))
To do away with this warning, I'd have to specify "#:duplicates last"
for *every* module using (foo), because (foo) doesn't make much sense
without (oop goops)).
So, in short: can't class-name be a generic in the first place?
Regards, Andy
--
Andreas Rottmann | Rotty@ICQ | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
The best way to accelerate a Windows machine is at 9.81 m/s^2
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [GOOPS] make class-name a generic?
2004-02-23 14:04 [GOOPS] make class-name a generic? Andreas Rottmann
@ 2004-02-23 20:25 ` Mikael Djurfeldt
2004-02-24 2:11 ` Andreas Rottmann
0 siblings, 1 reply; 7+ messages in thread
From: Mikael Djurfeldt @ 2004-02-23 20:25 UTC (permalink / raw)
Cc: Guile Users, djurfeldt
Andreas Rottmann <a.rottmann@gmx.at> writes:
> In my code, I define a method on class-name. Since (oop goops) defines
> this as a simple procedure, I have to export the generic in my module,
> which leads to annyoing warnings about duplicate imports which are
> superfluous because the original class-name is still "there", just as
> a generic default method. Sample code:
>
> (define-module (foo)
> #:use-module (oop goops)
> #:export (<foo> class-name))
>
> (define-class <foo> ()
> (class-name #:getter class-name #:init-value 'foobar))
>
> (define-module (bar)
> #:use-module (oop goops)
> #:use-module (foo))
>
> (format #t "class-name of <foo> instance: ~S\n"
> (class-name (make <foo>)))
> (format #t "class-name of <foo>: ~S\n" (class-name <foo>))
>
> To do away with this warning, I'd have to specify "#:duplicates last"
> for *every* module using (foo), because (foo) doesn't make much sense
> without (oop goops)).
>
> So, in short: can't class-name be a generic in the first place?
Well, I suppose it could, even though it is a bit delicate to make the
change since class-name is used in the MOP for class redefinition.
Also, if we change the status of class-name, there are several other
class getter functions that we might want to change.
But first I'd like to better understand your needs. The code above is
not a real example since instances of <foo> aren't classes.
(class-name wants a class as argument.)
Could you explain why you need to add methods to class-name?
Best regards,
Mikael D.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [GOOPS] make class-name a generic?
2004-02-23 20:25 ` Mikael Djurfeldt
@ 2004-02-24 2:11 ` Andreas Rottmann
2004-02-24 14:59 ` Mikael Djurfeldt
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Rottmann @ 2004-02-24 2:11 UTC (permalink / raw)
Cc: Guile Users
Mikael Djurfeldt <mdj@mit.edu> writes:
> Andreas Rottmann <a.rottmann@gmx.at> writes:
>
>> In my code, I define a method on class-name. Since (oop goops) defines
>> this as a simple procedure, I have to export the generic in my module,
>> which leads to annyoing warnings about duplicate imports which are
>> superfluous because the original class-name is still "there", just as
>> a generic default method. Sample code:
>>
[snip]
>> To do away with this warning, I'd have to specify "#:duplicates last"
>> for *every* module using (foo), because (foo) doesn't make much sense
>> without (oop goops)).
>>
>> So, in short: can't class-name be a generic in the first place?
>
> Well, I suppose it could, even though it is a bit delicate to make the
> change since class-name is used in the MOP for class redefinition.
>
I don't want to define any methods on clases on it, just on plain
objects, so I guess it could be made generic, with the warning:
undefined behaviour results if you specialize class-name for
descendents of <class>.
> Also, if we change the status of class-name, there are several other
> class getter functions that we might want to change.
>
I haven't looked at that, but I slightly consider non-generics
namespace pollution: they take away a much greater extent of the
namespace -- a whole name -- as opposed to generics with a few
methods, which take only a part of the name's namespace.
> But first I'd like to better understand your needs. The code above is
> not a real example since instances of <foo> aren't classes.
> (class-name wants a class as argument.)
>
It is a "real example", since it is the cut-down version of real code.
> Could you explain why you need to add methods to class-name?
>
Because it's very convinient in my case: I'm working on G-Wrap-TNG (an
OO-rewrite using GOOPS of G-Wrap[0]) and in the G-Wrap environment, I
have "types", which can be attributed with a class name. Note that a
type is an instance in G-Wrap; so it would be very nice to be able to
say (class-name type) to get the class name associated with a type.
[0] http://yi.org/rotty/GWrap
Cheers, Andy
--
Andreas Rottmann | Rotty@ICQ | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
Any technology not indistinguishable from magic is insufficiently advanced.
-- Terry Pratchett
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [GOOPS] make class-name a generic?
2004-02-24 2:11 ` Andreas Rottmann
@ 2004-02-24 14:59 ` Mikael Djurfeldt
2004-02-24 15:43 ` Andreas Rottmann
0 siblings, 1 reply; 7+ messages in thread
From: Mikael Djurfeldt @ 2004-02-24 14:59 UTC (permalink / raw)
Cc: djurfeldt, Guile Users
Andreas Rottmann <a.rottmann@gmx.at> writes:
>> Could you explain why you need to add methods to class-name?
>>
> Because it's very convinient in my case: I'm working on G-Wrap-TNG (an
> OO-rewrite using GOOPS of G-Wrap[0]) and in the G-Wrap environment, I
> have "types", which can be attributed with a class name. Note that a
> type is an instance in G-Wrap; so it would be very nice to be able to
> say (class-name type) to get the class name associated with a type.
Well, the "class-" part of "class-name" is supposed to mean that it's
a selector for class objects. If type is not a class object, then I
would say it's not a good idea to use class-name on it. Why don't you
use the name "type-name"?
The reason I'm putting up some resistance here is that I would only
want to make the change if there is a real need, because this
particular set of selectors (class-name, class-slots etc) are so
fundamental that making them into generic functions would easily
complicate the reflexive structure of GOOPS. (They are a kind of
"base cases" in the MOP if you know what I mean.) I also have the
feeling that they are so specific in their function that it's
questionable if one really would like to hang new methods on them.
BTW, have you considered making your type objects real class objects?
I'm asking without having looked at your code, but I remember that
when I worked on a rudimentary C API for GOOPS, I had the idea to have
classes representing "foreign" objects, i.e. objects not allocated or
administered by GOOPS. That way one could perhaps more easily use
some of the facilities in GOOPS such as slot access and accessors.
M
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [GOOPS] make class-name a generic?
2004-02-24 14:59 ` Mikael Djurfeldt
@ 2004-02-24 15:43 ` Andreas Rottmann
2004-02-27 20:38 ` Mikael Djurfeldt
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Rottmann @ 2004-02-24 15:43 UTC (permalink / raw)
Cc: Guile Users, G-Wrap development
Mikael Djurfeldt <mdj@mit.edu> writes:
[ CC'ed g-wrap-dev, since Rob might be interested in that too ]
> Andreas Rottmann <a.rottmann@gmx.at> writes:
>
>>> Could you explain why you need to add methods to class-name?
>>>
>> Because it's very convinient in my case: I'm working on G-Wrap-TNG (an
>> OO-rewrite using GOOPS of G-Wrap[0]) and in the G-Wrap environment, I
>> have "types", which can be attributed with a class name. Note that a
>> type is an instance in G-Wrap; so it would be very nice to be able to
>> say (class-name type) to get the class name associated with a type.
>
> Well, the "class-" part of "class-name" is supposed to mean that it's
> a selector for class objects. If type is not a class object, then I
> would say it's not a good idea to use class-name on it. Why don't you
> use the name "type-name"?
>
Because g-wrap creates GOOPS classes for the types that have a
class-name (simply put). The class-name and the type-name of a type
are not necessarily the same.
> The reason I'm putting up some resistance here is that I would only
> want to make the change if there is a real need, because this
> particular set of selectors (class-name, class-slots etc) are so
> fundamental that making them into generic functions would easily
> complicate the reflexive structure of GOOPS. (They are a kind of
> "base cases" in the MOP if you know what I mean.) I also have the
> feeling that they are so specific in their function that it's
> questionable if one really would like to hang new methods on them.
>
I could always try to think of another name for the accessor, but
class-name seemed the best fit.
> BTW, have you considered making your type objects real class objects?
> I'm asking without having looked at your code,
>
Well, the code is not available yet. I'll commit a sneak preview to my
archive sonish, however.
> but I remember that when I worked on a rudimentary C API for GOOPS,
> I had the idea to have classes representing "foreign" objects,
> i.e. objects not allocated or administered by GOOPS. That way one
> could perhaps more easily use some of the facilities in GOOPS such
> as slot access and accessors.
>
The type objects I talk about are not runtime objects, but
wrapper-generation-time objects, used to describe the type for the
wrapper generator, which then spits out the C code that ends up
implementing the type (conversion C<->Guile, C value destruction,
...). I have a <gw-type> class with several associated generics which
are responsible for creating the code, which then are specialized for
various specific types, e.g. there is a <simple-type>, which allows to
for simple forms to be used for wrapping/unwrapping. <simple-type>s
are used for e.g. integers, booleans and other values with an
immediate representation in Scheme:
(define-class <simple-type> (<gw-ffi-type>)
(type-check #:init-keyword #:type-check)
(wrap #:init-keyword #:wrap)
(unwrap #:init-keyword #:unwrap))
[...]
(add-type! wrapset 'float
(make <simple-type>
#:c-type-name "float"
#:type-check '("SCM_NFALSEP(scm_number_p(" scm-var "))\n")
#:unwrap '(c-var "= scm_num2float(" scm-var ", 1,"
" \"gw:scm->float\");\n")
#:wrap '(scm-var "= scm_float2num(" c-var ");\n")
#:ffspec 'float))
The code currently does not create classes itself, but the class-name
is supposed to refer to a class generated "from outside". The
class-name feature is used by the guile-gobject bindings to create
methods specialized to the classes created by guile-gobject (which has
a built-in facility to create a GOOPS class for a GObject class). So
it would make sense to add #:class-name '<real> in the above make
invocation.
Hope that clears it up a bit.
Andy
--
Andreas Rottmann | Rotty@ICQ | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
Say NO to Software Patents! -- http://petition.eurolinux.org/
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [GOOPS] make class-name a generic?
2004-02-24 15:43 ` Andreas Rottmann
@ 2004-02-27 20:38 ` Mikael Djurfeldt
2004-02-28 12:47 ` Andreas Rottmann
0 siblings, 1 reply; 7+ messages in thread
From: Mikael Djurfeldt @ 2004-02-27 20:38 UTC (permalink / raw)
Cc: djurfeldt, G-Wrap development, Guile Users
Andreas Rottmann <a.rottmann@gmx.at> writes:
> (define-class <simple-type> (<gw-ffi-type>)
> (type-check #:init-keyword #:type-check)
> (wrap #:init-keyword #:wrap)
> (unwrap #:init-keyword #:unwrap))
>
> [...]
>
> (add-type! wrapset 'float
> (make <simple-type>
> #:c-type-name "float"
> #:type-check '("SCM_NFALSEP(scm_number_p(" scm-var "))\n")
> #:unwrap '(c-var "= scm_num2float(" scm-var ", 1,"
> " \"gw:scm->float\");\n")
> #:wrap '(scm-var "= scm_float2num(" c-var ");\n")
> #:ffspec 'float))
>
> The code currently does not create classes itself, but the class-name
> is supposed to refer to a class generated "from outside". The
> class-name feature is used by the guile-gobject bindings to create
> methods specialized to the classes created by guile-gobject (which has
> a built-in facility to create a GOOPS class for a GObject class). So
> it would make sense to add #:class-name '<real> in the above make
> invocation.
>
> Hope that clears it up a bit.
It does.
The situation is that we have two distinct functions, class-name of
GOOPS, which takes a class object and returns its name, and class-name
of <simple-type>, which takes a <simple-type> object and returns the
name of the class guile-gobject is supposed to create. The problem is
that of a name clash---both distinct functions are most suitably named
"class-name".
What you are asking for is to turn the GOOPS class-name getter into a
generic function so that you can distribute your getter method through
that function via the (oop goops) public interface to other modules.
While that is certainly possible, I think it's generally a better idea
to give distinct functions distinct names. What about type-name,
scm-type-name or goops-class-name?
I *do* sympathize with your criticism about name-space pollution.
Maybe a remedy would be to separate out bindings having to do with
GOOPS reflection into a (oop goops reflection) interface?
Best regards,
Mikael D.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [GOOPS] make class-name a generic?
2004-02-27 20:38 ` Mikael Djurfeldt
@ 2004-02-28 12:47 ` Andreas Rottmann
0 siblings, 0 replies; 7+ messages in thread
From: Andreas Rottmann @ 2004-02-28 12:47 UTC (permalink / raw)
Cc: Guile Users, G-Wrap development
Mikael Djurfeldt <mdj@mit.edu> writes:
> The situation is that we have two distinct functions, class-name of
> GOOPS, which takes a class object and returns its name, and class-name
> of <simple-type>, which takes a <simple-type> object and returns the
> name of the class guile-gobject is supposed to create. The problem is
> that of a name clash---both distinct functions are most suitably named
> "class-name".
>
> What you are asking for is to turn the GOOPS class-name getter into a
> generic function so that you can distribute your getter method through
> that function via the (oop goops) public interface to other modules.
>
Exactly.
> While that is certainly possible, I think it's generally a better idea
> to give distinct functions distinct names. What about type-name,
> scm-type-name or goops-class-name?
>
Well, types already have name in the context of a wrapset. I'm
considering making this the class-name if an additional has-class
attribute is set to #t and thus working around the issue, although
that approach is less flexible.
> I *do* sympathize with your criticism about name-space pollution.
> Maybe a remedy would be to separate out bindings having to do with
> GOOPS reflection into a (oop goops reflection) interface?
>
I think this is a good idea.
Andy
--
Andreas Rottmann | Rotty@ICQ | 118634484@ICQ | a.rottmann@gmx.at
http://yi.org/rotty | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint | DFB4 4EB4 78A4 5EEE 6219 F228 F92F CFC5 01FD 5B62
The best way to accelerate a Windows machine is at 9.81 m/s^2
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-02-28 12:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-23 14:04 [GOOPS] make class-name a generic? Andreas Rottmann
2004-02-23 20:25 ` Mikael Djurfeldt
2004-02-24 2:11 ` Andreas Rottmann
2004-02-24 14:59 ` Mikael Djurfeldt
2004-02-24 15:43 ` Andreas Rottmann
2004-02-27 20:38 ` Mikael Djurfeldt
2004-02-28 12:47 ` Andreas Rottmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).