From: Tobias Brandt <tob.brandt@googlemail.com>
To: Marko Rauhamaa <marko@pacujo.net>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: GOOPS constructors
Date: Tue, 22 Jul 2014 14:22:31 +0200 [thread overview]
Message-ID: <CAOOWqirhYFmwteUK9wzzWo7VLsXEhTckgMq1iiU+etzhw7U-uQ@mail.gmail.com> (raw)
In-Reply-To: <87d2cxoadc.fsf@elektro.pacujo.net>
[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]
Couldn't just define <square> like this:
(define-class <square> (<rectangle>))
then define a side method:
(define-method (side (@ <square>)) (slot-ref @ 'height))
This way, you're not storing the same information twice.
On 22 July 2014 14:18, Marko Rauhamaa <marko@pacujo.net> wrote:
>
> Consider this simple program:
>
> ========================================================================
> (use-modules
> (oop goops)
> (ice-9 optargs))
>
> (define-class <rectangle> ()
> (width #:accessor width #:init-keyword #:width)
> (height #:accessor height #:init-keyword #:height))
>
> (define-method (area (@ <rectangle>))
> (* (height @) (width @)))
>
> (define-class <square> (<rectangle>)
> (side #:accessor side #:init-keyword #:side))
>
> (define-method (initialize (@ <square>) args)
> (let-keywords
> args #f ((side #f))
> (next-method @ (list #:width side #:height side))))
>
> (format #t "~S\n" (area (make <square> #:side 3)))
> (format #t "~S\n" (side (make <square> #:side 3)))
> ========================================================================
>
> The program outputs:
>
> ========================================================================
> 9
> ERROR: Unbound slot in object #<<square> b76cfec0>
> ========================================================================
>
> I understand that by overriding <square>'s initialize method I'm losing
> the magic of the default initializer. How could I have the cake and eat
> it, too?
>
>
> Marko
>
>
[-- Attachment #2: Type: text/html, Size: 2185 bytes --]
next prev parent reply other threads:[~2014-07-22 12:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-22 12:18 GOOPS constructors Marko Rauhamaa
2014-07-22 12:22 ` Tobias Brandt [this message]
2014-07-22 13:03 ` Marko Rauhamaa
2014-07-22 13:09 ` Tobias Brandt
2014-07-22 13:15 ` Marko Rauhamaa
2014-07-23 15:02 ` Barry Fishman
2014-07-23 17:42 ` Marko Rauhamaa
[not found] ` <m3lhri21kk.fsf@barry_fishman.acm.org>
2014-07-25 10:26 ` Marko Rauhamaa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOOWqirhYFmwteUK9wzzWo7VLsXEhTckgMq1iiU+etzhw7U-uQ@mail.gmail.com \
--to=tob.brandt@googlemail.com \
--cc=guile-user@gnu.org \
--cc=marko@pacujo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).