guile-user
[Top][All Lists]
Advanced

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

Re: anyone define port types?


From: Jan Wedekind
Subject: Re: anyone define port types?
Date: Thu, 31 Mar 2016 21:42:04 +0100 (BST)
User-agent: Alpine 2.11 (DEB 23 2013-08-11)

On Thu, 31 Mar 2016, Marko Rauhamaa wrote:

Jan Wedekind <address@hidden>:

On Wed, 30 Mar 2016, Marko Rauhamaa wrote:
GOOPS' has the worst possible object model: objects are seen as mere
data records. The concept of a "slot" is an anathema to OOP.

Ok, I have updated the example to use accessor functions instead of
"slot-ref".

(get-x) is only a fig leaf for (slot-ref). In general, no user of an <a>
object should think the object holds a piece of information called x.
Instead, you should be interacting with the abstract object <a>.
Well, actually (get-x) is a generic as well. I.e. it is polymorphic and does not have to be a simple accessor for a slot. I.e. the accessor syntax is just a shortcut for declaring a generic for accessing a slot separately:

(use-modules (oop goops))
(define-class <a> () (x #:init-keyword #:x))
(define-method (get-x (self <a>)) (slot-ref self 'x))

"get-x" can be defined differently for each class and its implementation can be doing something different than accessing a slot.


Python people call it duck-typing.

Java, Go et al use interfaces.

Even C can do opaque structs.

C++ suffers from "private" data members, and GOOPS strips away even that
thin veil.

Here is an example using duck-typing with the generic "get-x":

(define-class <b> ())
(define-method (get-x (self <b>)) 123)
(define-method (use-duck-typing (x <object>)) (get-x x))
(use-duck-typing (make <a> #:x 3))
; => 3
(use-duck-typing (make <b>))
; => 123



reply via email to

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