unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Applicable GOOPS objects?
@ 2012-03-23 19:02 Mark H Weaver
  2012-03-24  3:36 ` Nala Ginrut
  2012-03-24  4:52 ` BT Templeton
  0 siblings, 2 replies; 7+ messages in thread
From: Mark H Weaver @ 2012-03-23 19:02 UTC (permalink / raw)
  To: guile-devel

Hello all,

I was chatting with the folks working on Python-on-Guile, and it seems
clear that they need the ability to create GOOPS objects that can
emulate procedures.  Otherwise they will probably end up creating an
entirely separate object system for Python, which would obviously be
suboptimal.

I think the most flexible approach is to add a standard generic function
'generic-apply' that gets called whenever someone tries to use a GOOPS
object as a procedure.  I guess 'procedure?' should return true for a
GOOPS object iff there exists an applicable method for 'generic-apply'.

What do you think?

I'd like to get this done quickly, because the Python-on-Guile folks
only have a couple of months to do their project, and they need to
decide on their data representation strategy ASAP.

    Thanks!
      Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Applicable GOOPS objects?
  2012-03-23 19:02 Applicable GOOPS objects? Mark H Weaver
@ 2012-03-24  3:36 ` Nala Ginrut
  2012-03-24  4:52 ` BT Templeton
  1 sibling, 0 replies; 7+ messages in thread
From: Nala Ginrut @ 2012-03-24  3:36 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1199 bytes --]

hi Mark!
I think this will enhance our multi-language feature. Other inner language
may need it later.
And I don't see any harm with this generic-apply.
Personally, I wish this could be done soon. Because I'm interested in
adding new inner language too. ;-)

Regards.

On Sat, Mar 24, 2012 at 3:02 AM, Mark H Weaver <mhw@netris.org> wrote:

> Hello all,
>
> I was chatting with the folks working on Python-on-Guile, and it seems
> clear that they need the ability to create GOOPS objects that can
> emulate procedures.  Otherwise they will probably end up creating an
> entirely separate object system for Python, which would obviously be
> suboptimal.
>
> I think the most flexible approach is to add a standard generic function
> 'generic-apply' that gets called whenever someone tries to use a GOOPS
> object as a procedure.  I guess 'procedure?' should return true for a
> GOOPS object iff there exists an applicable method for 'generic-apply'.
>
> What do you think?
>
> I'd like to get this done quickly, because the Python-on-Guile folks
> only have a couple of months to do their project, and they need to
> decide on their data representation strategy ASAP.
>
>    Thanks!
>       Mark
>
>

[-- Attachment #2: Type: text/html, Size: 1614 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Applicable GOOPS objects?
  2012-03-23 19:02 Applicable GOOPS objects? Mark H Weaver
  2012-03-24  3:36 ` Nala Ginrut
@ 2012-03-24  4:52 ` BT Templeton
  2012-03-24  6:23   ` Mark H Weaver
  2012-03-24 18:07   ` Mark H Weaver
  1 sibling, 2 replies; 7+ messages in thread
From: BT Templeton @ 2012-03-24  4:52 UTC (permalink / raw)
  To: guile-devel

Mark H Weaver <mhw@netris.org> writes:

> Hello all,
>
> I was chatting with the folks working on Python-on-Guile, and it seems
> clear that they need the ability to create GOOPS objects that can
> emulate procedures.  Otherwise they will probably end up creating an
> entirely separate object system for Python, which would obviously be
> suboptimal.
>
> I think the most flexible approach is to add a standard generic function
> 'generic-apply' that gets called whenever someone tries to use a GOOPS
> object as a procedure.  I guess 'procedure?' should return true for a
> GOOPS object iff there exists an applicable method for 'generic-apply'.
>
> What do you think?

GOOPS defines an <applicable-struct-class> metaclass for this (similar
to AMOP's funcallable-standard-class):

scheme@(guile-user)> (define-class <foo> (<applicable-struct>))
scheme@(guile-user)> ((make <foo> #:procedure car) '(1 2))
$1 = 1

Would it work to simply have all Python metaclasses inherit from
<applicable-struct-class>?

-- 
Inteligenta persono lernas la lingvon Esperanton rapide kaj facile.
Esperanto estas moderna, kultura lingvo por la mondo. Simpla, fleksebla,
belsona, Esperanto estas la praktika solvo de la problemo de universala
interkompreno. Lernu la interlingvon Esperanton!




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Applicable GOOPS objects?
  2012-03-24  4:52 ` BT Templeton
@ 2012-03-24  6:23   ` Mark H Weaver
  2012-03-24 18:07   ` Mark H Weaver
  1 sibling, 0 replies; 7+ messages in thread
From: Mark H Weaver @ 2012-03-24  6:23 UTC (permalink / raw)
  To: BT Templeton; +Cc: guile-devel

BT Templeton <bpt@hcoop.net> writes:

> Mark H Weaver <mhw@netris.org> writes:
>
>> Hello all,
>>
>> I was chatting with the folks working on Python-on-Guile, and it seems
>> clear that they need the ability to create GOOPS objects that can
>> emulate procedures.  Otherwise they will probably end up creating an
>> entirely separate object system for Python, which would obviously be
>> suboptimal.
[...]
>
> GOOPS defines an <applicable-struct-class> metaclass for this (similar
> to AMOP's funcallable-standard-class):
>
> scheme@(guile-user)> (define-class <foo> (<applicable-struct>))
> scheme@(guile-user)> ((make <foo> #:procedure car) '(1 2))
> $1 = 1
>
> Would it work to simply have all Python metaclasses inherit from
> <applicable-struct-class>?

Yes, I believe it will.  Thanks very much! :)

    Mark


PS: I notice that there's also 'scm_class_applicable_struct_with_setter'
    which is exported as SCM_API, but was apparently never implemented
    and is always NULL.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Applicable GOOPS objects?
  2012-03-24  4:52 ` BT Templeton
  2012-03-24  6:23   ` Mark H Weaver
@ 2012-03-24 18:07   ` Mark H Weaver
  2012-03-24 23:48     ` BT Templeton
  1 sibling, 1 reply; 7+ messages in thread
From: Mark H Weaver @ 2012-03-24 18:07 UTC (permalink / raw)
  To: BT Templeton; +Cc: guile-devel

BT Templeton <bpt@hcoop.net> writes:

> GOOPS defines an <applicable-struct-class> metaclass for this (similar
> to AMOP's funcallable-standard-class):
>
> scheme@(guile-user)> (define-class <foo> (<applicable-struct>))
> scheme@(guile-user)> ((make <foo> #:procedure car) '(1 2))
> $1 = 1
>
> Would it work to simply have all Python metaclasses inherit from
> <applicable-struct-class>?

On second thought, I see a problem with this idea: it would mean that
'procedure?' would return true for _any_ Python object.

In order to avoid this problem, the Python implementation would need to
know at class-creation time whether the __call__ method will be
supported.  My knowledge of Python is very rusty, but I'm pretty sure
that the user could add a __call__ method at any time.

      Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Applicable GOOPS objects?
  2012-03-24 18:07   ` Mark H Weaver
@ 2012-03-24 23:48     ` BT Templeton
  2012-03-25 13:50       ` Mark H Weaver
  0 siblings, 1 reply; 7+ messages in thread
From: BT Templeton @ 2012-03-24 23:48 UTC (permalink / raw)
  To: guile-devel

Mark H Weaver <mhw@netris.org> writes:

> BT Templeton <bpt@hcoop.net> writes:
>
>> GOOPS defines an <applicable-struct-class> metaclass for this (similar
>> to AMOP's funcallable-standard-class):
>>
>> scheme@(guile-user)> (define-class <foo> (<applicable-struct>))
>> scheme@(guile-user)> ((make <foo> #:procedure car) '(1 2))
>> $1 = 1
>>
>> Would it work to simply have all Python metaclasses inherit from
>> <applicable-struct-class>?
>
> On second thought, I see a problem with this idea: it would mean that
> 'procedure?' would return true for _any_ Python object.
>
> In order to avoid this problem, the Python implementation would need to
> know at class-creation time whether the __call__ method will be
> supported.  My knowledge of Python is very rusty, but I'm pretty sure
> that the user could add a __call__ method at any time.

True, but in GOOPS you'd have to change the object's class anyway to add
a slot, I think. So the new dynamically-instantiated class could inherit
from both the original class and <applicable-struct>.

-- 
Inteligenta persono lernas la lingvon Esperanton rapide kaj facile.
Esperanto estas moderna, kultura lingvo por la mondo. Simpla, fleksebla,
belsona, Esperanto estas la praktika solvo de la problemo de universala
interkompreno. Lernu la interlingvon Esperanton!




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Applicable GOOPS objects?
  2012-03-24 23:48     ` BT Templeton
@ 2012-03-25 13:50       ` Mark H Weaver
  0 siblings, 0 replies; 7+ messages in thread
From: Mark H Weaver @ 2012-03-25 13:50 UTC (permalink / raw)
  To: BT Templeton; +Cc: guile-devel

BT Templeton <bpt@hcoop.net> writes:

> Mark H Weaver <mhw@netris.org> writes:
>
>> BT Templeton <bpt@hcoop.net> writes:
>>
>>> Would it work to simply have all Python metaclasses inherit from
>>> <applicable-struct-class>?
>>
>> On second thought, I see a problem with this idea: it would mean that
>> 'procedure?' would return true for _any_ Python object.
>>
>> In order to avoid this problem, the Python implementation would need to
>> know at class-creation time whether the __call__ method will be
>> supported.  My knowledge of Python is very rusty, but I'm pretty sure
>> that the user could add a __call__ method at any time.
>
> True, but in GOOPS you'd have to change the object's class anyway to add
> a slot, I think. So the new dynamically-instantiated class could inherit
> from both the original class and <applicable-struct>.

I don't know why it would be necessary to redefine the class in order to
add a method, but this is an interesting idea nonetheless.  One
potential issue is that references to the old class may linger, but that
can most likely be addressed by adding a level of indirection to class
references in Python.  It's not an ideal solution, but it should work.

    Thanks!
      Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-03-25 13:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-23 19:02 Applicable GOOPS objects? Mark H Weaver
2012-03-24  3:36 ` Nala Ginrut
2012-03-24  4:52 ` BT Templeton
2012-03-24  6:23   ` Mark H Weaver
2012-03-24 18:07   ` Mark H Weaver
2012-03-24 23:48     ` BT Templeton
2012-03-25 13:50       ` Mark H Weaver

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).