From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.devel Subject: Re: Add support for record types in GOOPS methods? Date: Tue, 21 Oct 2014 17:37:53 +0200 Message-ID: References: <8d1tq1fp1q.fsf@freestation00.office.fsf.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bfeb51c55ff2f0505f09d6e X-Trace: ger.gmane.org 1413905953 22282 80.91.229.3 (21 Oct 2014 15:39:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 Oct 2014 15:39:13 +0000 (UTC) Cc: guile-devel To: Dave Thompson Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Oct 21 17:39:06 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XgbWb-0008H8-Jv for guile-devel@m.gmane.org; Tue, 21 Oct 2014 17:39:05 +0200 Original-Received: from localhost ([::1]:51554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgbWb-0006Zg-93 for guile-devel@m.gmane.org; Tue, 21 Oct 2014 11:39:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgbVY-0005F4-S0 for guile-devel@gnu.org; Tue, 21 Oct 2014 11:38:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgbVT-0001B0-KG for guile-devel@gnu.org; Tue, 21 Oct 2014 11:38:00 -0400 Original-Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:36188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgbVT-0001AT-Ak for guile-devel@gnu.org; Tue, 21 Oct 2014 11:37:55 -0400 Original-Received: by mail-wi0-f181.google.com with SMTP id hi2so2268297wib.2 for ; Tue, 21 Oct 2014 08:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Pyub3Nq8jhiiZFlisFwdyaHsX0ScdqsL7hh2PhTXnag=; b=A1hVeBdTPkqTb/s/kC79nV+YV9BFXW3Cm3AnFc6OyCsc6D31xAzvK27jI/eGEKrc2I YBeHBAeVCvccahvRco+udlqvuJNDz1/BUlNvsFcMf/k/rCb0V6ifoVUb+gdFjOADLQ36 j7PT7yqLihzizezdTcV2ZmESXrrngNnD/MEs+k3YLn2VOaeTBTeXdvFnxt10BY2DnWCi vy61riDR3jjAmyLAqDysYoIeA2Lo4sqItS1+R8xsRY1ncBWy5QlE4GAVctlqJavsHjKJ vNWS4gzRK7OJrucPjsz7wuFt/J63W1wSgjDQg//hivsp+10BTgid/LI7vklB9uOlVWzN sMUA== X-Received: by 10.194.103.230 with SMTP id fz6mr39172215wjb.53.1413905873500; Tue, 21 Oct 2014 08:37:53 -0700 (PDT) Original-Received: by 10.194.238.97 with HTTP; Tue, 21 Oct 2014 08:37:53 -0700 (PDT) In-Reply-To: <8d1tq1fp1q.fsf@freestation00.office.fsf.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::235 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17591 Archived-At: --047d7bfeb51c55ff2f0505f09d6e Content-Type: text/plain; charset=UTF-8 2014-10-21 16:57 GMT+02:00 Dave Thompson : > Hello all, > > Last night, I encountered what I consider to be a frustrating limitation > of GOOPS methods: They do not support record type descriptors, only > classes. This makes it difficult to take advantage of generic > procedures without also buying into the rest of the GOOPS system. > > Here's some code that I wish would work: > > (define-record-type > (make-foo bar) > foo? > (bar foo-bar)) > > (define-method (foobar (foo )) > (foo-bar foo)) > > The error thrown by `define-method' is: > > ERROR: In procedure class-direct-methods: > ERROR: In procedure slot-ref: Wrong type argument in position 1 > (expecting instance): #> > > There is an ugly workaround. You can use `class-of' on an instance of a > record type to get a class in return. > > This code works, but is unideal: > > (define-record-type > (make-foo bar) > foo? > (bar foo-bar)) > > (define (class-of (make-foo #f))) > > (define-method (foobar (foo )) > (foo-bar foo)) > > I don't know very much about GOOPS, so I am seeking help. Would it make > sense for `define-method' to work the way I want? If so, could anyone > suggest a way to make `define-method' to DTRT for record types? Perhaps > it could auto-generate and cache the class from the record type > descriptor, but I'm not sure how since the current workaround requires > an instance of that record. > > Hi! As I managed to find out, the (define-record-type t ...) also introduces a GOOPS class named . Following your example, you'd need to define your method in the following way: (define-method (foobar (foo <>)) (foo-bar foo)) I don't think any further changes are needed (perhaps a section in the documentation would be nice) HTH --047d7bfeb51c55ff2f0505f09d6e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
2014= -10-21 16:57 GMT+02:00 Dave Thompson <dthompson2@worcester.edu&= gt;:
Hello all,

Last night, I encountered what I consider to be a frustrating limitation of GOOPS methods: They do not support record type descriptors, only
classes.=C2=A0 This makes it difficult to take advantage of generic
procedures without also buying into the rest of the GOOPS system.

Here's some code that I wish would work:

=C2=A0 (define-record-type <foo>
=C2=A0 =C2=A0 (make-foo bar)
=C2=A0 =C2=A0 foo?
=C2=A0 =C2=A0 (bar foo-bar))

=C2=A0 (define-method (foobar (foo <foo>))
=C2=A0 =C2=A0 (foo-bar foo))

The error thrown by `define-method' is:

=C2=A0 ERROR: In procedure class-direct-methods:
=C2=A0 ERROR: In procedure slot-ref: Wrong type argument in position 1 (exp= ecting instance): #<record-type <foo>>

There is an ugly workaround.=C2=A0 You can use `class-of' on an instanc= e of a
record type to get a class in return.

This code works, but is unideal:

=C2=A0 (define-record-type <foo>
=C2=A0 =C2=A0 (make-foo bar)
=C2=A0 =C2=A0 foo?
=C2=A0 =C2=A0 (bar foo-bar))

=C2=A0 (define <foo-class> (class-of (make-foo #f)))

=C2=A0 (define-method (foobar (foo <foo-class>))
=C2=A0 =C2=A0 (foo-bar foo))

I don't know very much about GOOPS, so I am seeking help.=C2=A0 Would i= t make
sense for `define-method' to work the way I want?=C2=A0 If so, could an= yone
suggest a way to make `define-method' to DTRT for record types?=C2=A0 P= erhaps
it could auto-generate and cache the class from the record type
descriptor, but I'm not sure how since the current workaround requires<= br> an instance of that record.

=C2=A0
Hi!
As I managed to find out, the (define-record-type t ...) also intr= oduces a GOOPS class named <t>. Following your example, you'd nee= d to define your method in the following way:

(define-method (fo= obar (foo <<foo>>))
=C2=A0 =C2=A0 (foo-bar foo))

I do= n't think any further changes are needed (perhaps a section in the docu= mentation would be nice)

HTH

--047d7bfeb51c55ff2f0505f09d6e--