[Oberon] Class Methods Vs. Procedure variables in Records

Skulski, Wojciech skulski at pas.rochester.edu
Wed Mar 1 02:14:46 CET 2017


I believe Component pascal is the best. I wrote lots of code in CP and it was just perfect. It is my opinion. 

Wojtek
________________________________________
From: Oberon [oberon-bounces at lists.inf.ethz.ch] on behalf of Richard Hable [informujo at aon.at]
Sent: Tuesday, February 28, 2017 2:23 PM
To: oberon at lists.inf.ethz.ch
Subject: Re: [Oberon] Class Methods Vs. Procedure variables in Records

Am 2017-02-27 um 15:05 schrieb Andreas Pirklbauer:

> Wirth remains: these languages are still too complex. Why again are
> there separate concepts for structs (=records), classes (=pointers to
> records), modules, and protocols, and extensions, and and .. in Swift,
> when exactly two would do (records for data structuring and modules for
> information hiding)?

On the other hand, if you use Oberon or Oberon-2, you need at least
three definitions in order to define a simple class: the module
containing the class, a record type containing its member variables, and
a pointer type referring to the record.

And if you want dynamic method calls in Oberon according to the "do"
pattern, you need to define an additional method record type and a
pointer type referring to it; plus some helper variables and methods to
initialize everything.

Then, a simple Java source file like this:

class User {
        public Date birthDate;
        public int currentAge(){
                ...
        }
}

becomes something like this:

MODULE Users;

TYPE
        User* = POINTER TO UserDesc;
        UserDesc* = RECORD
                birthDate*: Date;
                do*: UserMethod;
        END;

        UserMethod* = POINTER TO UserMethodDesc;
        UserMethodDesc* = RECORD
                currentAge*: PROCEDURE(): INTEGER;
        END;

VAR
        userMethod: UserMethod;

PROCEDURE CurrentAge(): INTEGER;
        BEGIN
                ...
        END CurrentAge;

PROCEDURE NewUser*(): User;
        VAR
                user: User;
        BEGIN
                NEW (user);
                user.do := userMethod;
                RETURN user;
        END NewUser;

BEGIN
        NEW (userMethod);
        userMethod.currentAge := CurrentAge;
END Users.

(all syntax from memory)

Richard


--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=DwICAg&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=t0kLIHd4NcbgOWeWaVzG2kRQTcOv-hJM8fFPVisCHCk&s=8zM35VudlAfNTk-1w3qgAla3weBia-_Z0A6vA5-l81k&e=


More information about the Oberon mailing list