guile-user
[Top][All Lists]
Advanced

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

Re: GOOPS constructors


From: Tobias Brandt
Subject: Re: GOOPS constructors
Date: Tue, 22 Jul 2014 15:09:34 +0200

I don't have access to guile currently, so I can't try this. But I think you can just pass path, code, and fs to next-method.
They should eventually end up in the default initialize.

(define-method (initialize (@ <file-error>) args)
  (let-keywords
   args #f ((path #f) (code #f) (fs #f))
   (next-method @ (list #:msg (format #f "File error in ~S (~S)" path code) #:path path #:code code #:fs fs))))


On 22 July 2014 15:03, Marko Rauhamaa <address@hidden> wrote:
Tobias Brandt <address@hidden>:

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

Well, I was trying to find a simple toy example to demonstrate the need,
but maybe I'll need to find a more compelling one.

How about:

========================================================================
(define-class <error> ()
  (msg #:getter msg #:init-keyword #:msg))

(define-class <file-error> (<error>)
  (path #:getter path #:init-keyword #:path)
  (code #:getter code #:init-keyword #:code)
  (fs #:getter fs #:init-keyword #:fs))

(define-method (initialize (@ <file-error>) args)
  (let-keywords
   args #f ((path #f) (code #f) (fs #f))
   (next-method @ (list #:msg (format #f "File error in ~S (~S)" path code)))))
========================================================================

How do I now write the getters for path, code and fs?


Marko


reply via email to

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